create_domain.7

来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· 7 代码 · 共 114 行

7
114
字号
.\\" auto-generated by docbook2man-spec $Revision: 1.1.1.1 $.TH "CREATE DOMAIN" "" "2008-01-03" "SQL - Language Statements" "SQL Commands".SH NAMECREATE DOMAIN \- define a new domain.SH SYNOPSIS.sp.nfCREATE DOMAIN \fIname\fR [ AS ] \fIdata_type\fR    [ DEFAULT \fIexpression\fR ]    [ \fIconstraint\fR [ ... ] ]where \fIconstraint\fR is:[ CONSTRAINT \fIconstraint_name\fR ]{ NOT NULL | NULL | CHECK (\fIexpression\fR) }.sp.fi.SH "DESCRIPTION".PP\fBCREATE DOMAIN\fR creates a new domain. A domain isessentially a data type with optional constraints (restrictions onthe allowed set of values).The user who defines a domain becomes its owner..PPIf a schema name is given (for example, CREATE DOMAINmyschema.mydomain ...) then the domain is created in thespecified schema. Otherwise it is created in the current schema.The domain name must be unique among the types and domains existingin its schema..PPDomains are useful for abstracting common constraints on fields intoa single location for maintenance. For example, several tables mightcontain email address columns, all requiring the same CHECK constraintto verify the address syntax.Define a domain rather than setting up each table's constraintindividually..SH "PARAMETERS".TP\fB\fIname\fB\fRThe name (optionally schema-qualified) of a domain to be created..TP\fB\fIdata_type\fB\fRThe underlying data type of the domain. This may include arrayspecifiers..TP\fBDEFAULT \fIexpression\fB\fRThe DEFAULT clause specifies a default value forcolumns of the domain data type. The value is anyvariable-free expression (but subqueries are not allowed).The data type of the default expression must match the datatype of the domain. If no default value is specified, thenthe default value is the null value.The default expression will be used in any insert operationthat does not specify a value for the column. If a defaultvalue is defined for a particular column, it overrides anydefault associated with the domain. In turn, the domaindefault overrides any default value associated with theunderlying data type..TP\fBCONSTRAINT \fIconstraint_name\fB\fRAn optional name for a constraint. If not specified,the system generates a name..TP\fBNOT NULL\fRValues of this domain are not allowed to be null..TP\fBNULL\fRValues of this domain are allowed to be null. This is the default.This clause is only intended for compatibility withnonstandard SQL databases. Its use is discouraged in newapplications..TP\fBCHECK (\fIexpression\fB)\fRCHECK clauses specify integrity constraints or testswhich values of the domain must satisfy.Each constraint must be an expressionproducing a Boolean result. It should use the key word VALUEto refer to the value being tested.Currently, CHECK expressions cannot containsubqueries nor refer to variables other than VALUE..SH "EXAMPLES".PPThis example creates the \fBus_postal_code\fR data type andthen uses the type in a table definition. A regular expression testis used to verify that the value looks like a valid US postal code..sp.nfCREATE DOMAIN us_postal_code AS TEXTCHECK(   VALUE ~ '^\\\\d{5}$'OR VALUE ~ '^\\\\d{5}-\\\\d{4}$');CREATE TABLE us_snail_addy (  address_id SERIAL PRIMARY KEY,  street1 TEXT NOT NULL,  street2 TEXT,  street3 TEXT,  city TEXT NOT NULL,  postal us_postal_code NOT NULL);.sp.fi.SH "COMPATIBILITY".PPThe command \fBCREATE DOMAIN\fR conforms to the SQLstandard..SH "SEE ALSO"ALTER DOMAIN [\fBalter_domain\fR(7)], DROP DOMAIN [\fBdrop_domain\fR(l)]

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?