CHECK Conditions on User-Defined Data Types

You can attach CHECK conditions to user-defined data types. Columns defined on those data types inherit the CHECK conditions. A CHECK condition explicitly specified for a column overrides the CHECK condition from a user-defined data type.

When defining a CHECK condition on a user-defined data type, any variable prefixed with the @ sign is replaced by the name of the column when the CHECK condition is evaluated. For example, the following user-defined data type accepts only positive integers:

CREATE DATATYPE posint INT
CHECK ( @col > 0 ) 

You can use any variable name prefixed with @ instead of @col. Any column defined using the posint data type accepts only positive integers unless it has a different explicitly specified CHECK condition.

An ALTER TABLE statement with the DELETE CHECK clause deletes all CHECK conditions from the table definition, including those inherited from user-defined data types.

For information on user-defined data types, see Reference: Building Blocks, Tables, and Procedures.