CREATE DOMAIN 中文man页面

系统
CREATE DOMAIN 创建一个新的数据域。 定义域的用户成为其所有者。

NAME

CREATE DOMAIN - 定义一个新域  

SYNOPSIS

CREATE DOMAIN name [AS] data_type
    [ DEFAULT expression ]
    [ constraint [ ... ] ]

where constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL | CHECK (expression) }

DESCRIPTION 描述

CREATE DOMAIN 创建一个新的数据域。 定义域的用户成为其所有者。


 如果给出一个模式名称(比如,CREATE DOMAIN myschema.mydomain ...), 那么该域是在指定的模式中创建的。否则它会在当前模式中创建。 域名字必需在其所在模式中的现有类型和域中***。


 域可以便于我们把不同表之间的公共域抽取到一个位置进行维护。 比如,一个电子邮件地址字段可能在多个表中使用,所有的都是同样的属性。 我们可以定义并使用一个域,而不是分别设置每个表的约束。  

PARAMETERS 参数

name

 要创建的域名字(可以有模式修饰)。
data_type

 域的下层数据类型。它可以包含数组声明字。
DEFAULT expression
DEFAULT 子句为域数据类型的字段声明一个缺省值。 该值是任何不含变量的表达式(但不允许子查询)。 缺省表达式的数据类型必需匹配域的数据类型。如果没有声明缺省值, 那么缺省值就是空值。


 缺省表达式将用在任何不为该字段声明数值的插入操作。 如果为特定的字段声明了缺省值,那么它覆盖任何和该域相关联的缺省值。 然后,域的缺省覆盖任何与下层数据类型相关的缺省。

CONSTRAINT constraint_name

 一个约束的可选名称。如果没有声明,系统生成一个名字。
NOT NULL

 这个域的数值不允许为 NULL。
NULL

 这个域的数值允许为空。它是缺省。
 
 这个子句只是用于和非标准的 SQL 数据库兼容用。 我们不建议在新的应用中使用它。
CHECK (expression)

 CHECK 子句声明完整性约束或者是测试,域地数值必须满足这些要求。 每个约束必须是一个生成一个布尔结果的表达式。它应该使用名字 VALUE  来引用被测试的数值。


 目前,CHECK 表达式不能包含子查询,也不能引用除 VALUE 之外的变量。

EXAMPLES 例子


 这个例子创建了 country_code 数据类型并且在一个表定义中使用了该类型:

CREATE DOMAIN country_code char(2) NOT NULL;
CREATE TABLE countrylist (id integer, country country_code);

COMPATIBILITY 兼容性

CREATE DOMAIN 命令符合 SQL 标准。  

SEE ALSO 参见

DROP DOMAIN [drop_domain(7)]  

#p#

NAME

CREATE DOMAIN - define a new domain

SYNOPSIS

CREATE DOMAIN name [AS] data_type
    [ DEFAULT expression ]
    [ constraint [ ... ] ]

where constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL | CHECK (expression) }

DESCRIPTION

CREATE DOMAIN creates a new data domain. The user who defines a domain becomes its owner.

If a schema name is given (for example, CREATE DOMAIN myschema.mydomain ...) then the domain is created in the specified schema. Otherwise it is created in the current schema. The domain name must be unique among the types and domains existing in its schema.

Domains are useful for abstracting common fields between tables into a single location for maintenance. For example, an email address column may be used in several tables, all with the same properties. Define a domain and use that rather than setting up each table's constraints individually.  

PARAMETERS

name
The name (optionally schema-qualified) of a domain to be created.
data_type
The underlying data type of the domain. This may include array specifiers.
DEFAULT expression
The DEFAULT clause specifies a default value for columns of the domain data type. The value is any variable-free expression (but subqueries are not allowed). The data type of the default expression must match the data type of the domain. If no default value is specified, then the default value is the null value.

The default expression will be used in any insert operation that does not specify a value for the column. If a default value is defined for a particular column, it overrides any default associated with the domain. In turn, the domain default overrides any default value associated with the underlying data type.

CONSTRAINT constraint_name
An optional name for a constraint. If not specified, the system generates a name.
NOT NULL
Values of this domain are not allowed to be null.
NULL
Values of this domain are allowed to be null. This is the default.

This clause is only intended for compatibility with nonstandard SQL databases. Its use is discouraged in new applications.

CHECK (expression)
CHECK clauses specify integrity constraints or tests which values of the domain must satisfy. Each constraint must be an expression producing a Boolean result. It should use the name VALUE to refer to the value being tested.

Currently, CHECK expressions cannot contain subqueries nor refer to variables other than VALUE.

EXAMPLES

This example creates the country_code data type and then uses the type in a table definition:

CREATE DOMAIN country_code char(2) NOT NULL;
CREATE TABLE countrylist (id integer, country country_code);

COMPATIBILITY

The command CREATE DOMAIN conforms to the SQL standard.  

SEE ALSO

DROP DOMAIN [drop_domain(7)]

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 14:19:14

DROP DOMAIN中文man

2011-08-24 09:22:30

alter_domai中文man

2011-08-24 13:26:19

CREATE SEQU中文man

2011-08-24 13:39:44

CREATE TYPE中文man

2011-08-24 11:18:53

CREATE LANG中文man

2011-08-24 11:23:20

CREATE OPER中文man

2011-08-24 13:23:10

CREATE SCHE中文man

2011-08-24 11:10:17

CREATE GROU中文man

2011-08-24 10:59:19

CREATE DATA中文man

2011-08-24 11:05:36

CREATE FUNC中文man

2011-08-24 11:31:47

CREATE RULE中文man

2011-08-24 13:36:25

CREATE TRIG中文man

2011-08-24 13:46:39

CREATE VIEW中文man

2011-08-24 10:56:32

CREATE CONV中文man

2011-08-24 10:46:36

CREATE AGGR中文man

2011-08-24 11:15:24

CREATE INDE中文man

2011-08-24 13:29:20

CREATE TABL中文man

2011-08-24 13:43:09

CREATE USER中文man

2011-08-24 13:32:56

CREATE TABL中文man

2011-08-24 10:50:05

create_cast中文man
点赞
收藏

51CTO技术栈公众号