Domains are aliases for built-in data types, including precision and scale values where applicable.
Domains, also called user-defined data types, allow columns throughout a database to be automatically defined on the same data type, with the same NULL or NOT NULL condition. This encourages consistency throughout the database.
Domains are created using the CREATE DOMAIN statement. For a full description of the syntax, see CREATE DOMAIN statement.
The following statement creates a data type named street_address, which is a 35-character string.
CREATE DOMAIN street_address CHAR( 35 )
CREATE DATATYPE can be used as an alternative to CREATE DOMAIN, but is not recommended, as CREATE DOMAIN is the syntax used in the draft SQL/3 standard.
Resource authority is required to create data types. Once a data type is created, the user ID that executed the CREATE DOMAIN statement is the owner of that data type. Any user can use the data type, and unlike other database objects, the owner name is never used to prefix the data type name.
The street_address data type may be used in exactly the same way as any other data type when defining columns. For example, the following table with two columns has the second column as a street_address column:
CREATE TABLE twocol (id INT, street street_address)
Domains can be dropped by their owner or by the DBA using the DROP DOMAIN statement:
DROP DOMAIN street_address
This statement can be carried out only if the data type is not used in any table in the database.
Named constraints and defaults In Sybase IQ, user-defined data types are created with a base data type, and optionally a NULL or NOT NULL condition. Named constraints and named defaults are not supported.
Creating data types In Sybase IQ, 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.