CREATE DOMAIN
Defines a new domain.
Synopsis
CREATE DOMAIN <name> [AS] <data_type>
[ COLLATE <collation> ]
[ DEFAULT <expression> ]
[ <constraint> [ ... ] ]
-- where <constraint> is:
[ CONSTRAINT <constraint_name> ]
{ NOT NULL | NULL | CHECK (<expression>) }
Description
CREATE DOMAIN
creates a new domain. A domain is essentially a data type with optional constraints (restrictions on the allowed set of values). 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 data types and domains existing in its schema.
Domains are useful for abstracting common constraints on fields into a single location for maintenance. For example, several tables might contain email address columns, all requiring the same CHECK
constraint to verify the address syntax. Define a domain rather than setting up each table's constraint individually.
To be able to create a domain, you must have USAGE
privilege on the underlying type.