ASA SQL Reference
SQL Statements
Use this statement to create a domain in a database.
CREATE { DOMAIN | DATATYPE } [ AS ] domain-name data-type
[ [ NOT ] NULL ]
[ DEFAULT default-value ]
[ CHECK ( condition ) ]
domain-name : identifier
data-type : built-in data type, with precision and scale
DOMAIN | DATATYPE It is recommended that you use CREATE DOMAIN, rather than CREATE DATATYPE because CREATE DOMAIN is the ANSI/ISO SQL3 term.
NULL By default, domains allow NULLs unless the allow_nulls_by_default option is set to OFF. In this case, new domains by default do not allow NULLs. The nullability of a column created on a domain depends on the setting of the definition of the domain, not on the setting of the allow_nulls_by_default option when the column is referenced. Any explicit setting of NULL or NOT NULL in the column definition overrides the domain setting.
CHECK clause When creating a CHECK condition, you can use a variable name prefixed with the @ sign in the condition. When the data type is used in the definition of a column, such a variable is replaced by the column name. This allows CHECK conditions to be defined on data types and used by columns of any name.
Domains are aliases for built-in data types, including precision and scale values where applicable. They improve convenience and encourage consistency in the database.
Domains are objects within the database. Their names must conform to the rules for identifiers. Domain names are always case insensitive, as are built-in data type names.
The user who creates a data type is automatically made the owner of that data type. No owner can be specified in the CREATE DATATYPE statement. The domain name must be unique, and all users can access the data type without using the owner as prefix.
Domains can have CHECK conditions and DEFAULT values, and you can indicate whether the data type permits NULL values or not. These conditions and values are inherited by any column defined on the data type. Any conditions or values explicitly specified on the column override those specified for the data type.
To drop the data type from the database, use the DROP statement. You must be either the owner of the data type or have DBA authority in order to drop a domain.
Must have RESOURCE authority.
Automatic commit.
SQL/92 Intermediate-level feature.
SQL/99 SQL/foundation feature outside of core SQL.
Sybase Not supported by Adaptive Server Enterprise. Transact-SQL provides similar functionality using the sp_addtype system procedure and the CREATE DEFAULT and CREATE RULE statements.
The following statement creates a data type named address, which holds a 35-character string, and which may be NULL.
CREATE DOMAIN address CHAR( 35 ) NULL
The following statement creates a data type named id, which does not allow NULLS, and which is autoincremented by default.
CREATE DOMAIN id INT NOT NULL DEFAULT AUTOINCREMENT