Chapter 7 SQL Data Types
287
Many of the attributes associated with columns, such as allowing NULL
values, having a DEFAULT value, and so on, can be built into a domain.
Any column that is defined on the data type automatically inherits the NULL
setting, CHECK condition, and DEFAULT values. This allows uniformity to
be built into columns with a similar meaning throughout a database.
For example, many primary key columns in the sample database are integer
columns holding ID numbers. The following statement creates a data type
that may be useful for such columns:
CREATE DOMAIN id INT
NOT NULL
DEFAULT AUTOINCREMENT
CHECK( @col > 0 )
Any column created using the data type id is not allowed to hold NULLs,
defaults to an auto-incremented value, and must hold a positive number. Any
identifier could be used instead of col in the @col variable.
The attributes of the data type can be overridden if needed by explicitly
providing attributes for the column. A column created on data type id with
NULL values explicitly allowed does allow NULLs, regardless of the setting
in the id data type.
♦
Named constraints and defaults In Adaptive Server Anywhere,
domains are created with a base data type, and optionally a NULL or
NOT NULL condition, a default value, and a CHECK condition. Named
constraints and named defaults are not supported.
♦
Creating data types In Adaptive Server Anywhere, you can use the
sp_addtype system procedure to add a domain, or you can use the
CREATE DOMAIN statement. In Adaptive Server Enterprise, you must
use sp_addtype.
Constraints and
defaults with
domains
Compatibility