Chapter 1: Creating
Chapter 1: Creating
Chapter 1: Creating
User-defined data types are simply a shorthand notation for the full column def-
inition. Ease of coding is the only real advantage, and there are several
disadvantages. First of all, a user-defined data type cannot be dropped or
changed without dropping all the references to it first. Second, a user-defined
data type hides the true column definition from the application programmer, and
that information is often important when writing applications. Third, constraint
names cannot be used so its hard to make the error messages meaningful.
Finally, except for the built-in base data type, all the properties of a
user-defined data type can be overridden in the CREATE TABLE. Here is an
example where the INSERT puts an empty string into address_2 and NULL into
address_3 even though those values deviate from the CREATE DOMAIN
definition:
CREATE DOMAIN address AS VARCHAR ( 100 )
NOT NULL
DEFAULT ''
CHECK ( LENGTH ( TRIM ( @col ) ) > 0 );