SYNOPSIS
CREATE DOMAIN name [AS] data_type [ DEFAULT expression ] [ constraint [ ... ] ] where constraint is: [ CONSTRAINT constraint_name ] { NOT NULL | NULL | CHECK (expression) }
DESCRIPTION Description
CREATE DOMAIN creates a new data field. User-defined domain becomes its owner.
If a schema name is given (for example, CREATE DOMAIN myschema.mydomain ...), then the domain is created in the specified mode. Otherwise it is created in the current schema. The domain name must it in mode types and domains existing unique.
Domains are useful for the public domain between different tables to extract a position for maintenance. For example, an e-mail address field may be used in multiple tables, all are the same attributes. We can define and use a domain, rather than setting up each table's constraints.
PARAMETERS Parameters
- name
-
The domain name to be created (schema-qualified). - data_type
-
Underlying data type field. It can contain an array declarations word. - DEFAULT expression
-
DEFAULT clause domain data type field declaration a default value. The value is any variable-free expression (but subqueries are not allowed). Default expression data type matches the data type field is necessary. If you do not declare a default value, the default value is null.
Default expression will be used in any insert the value for the column. If you declare a default value for a particular field, it overrides any default value associated with the domain of. Then, the default domain associated with the underlying overrides any default data type. - CONSTRAINT constraint_name
-
An optional name constraints. If not specified, the system generates a name. - NOT NULL
-
The value of this domain are not allowed to NULL. - NULL
-
The value of this field is allowed to be null. It is the default.
This clause is only used for non-standard SQL databases and is compatible with. We do not recommend using it in new applications. - CHECK ( expression )
-
CHECK clause declaration integrity constraints or tests, the value field must meet these requirements. Each constraint must be a result of a boolean expression. It should use the name VALUE to refer to the value being tested.
Currently, CHECK expressions can not contain subqueries nor refer to variables other than VALUE of.
EXAMPLES Examples
This example creates country_code data type and the type used in a table definition:
CREATE DOMAIN country_code char(2) NOT NULL; CREATE TABLE countrylist (id integer, country country_code);