602SQL Documentation Index  

CREATE DOMAIN Statement

statement_CREATE_DOMAIN ::= CREATE [ IF NOT EXISTS ] DOMAIN [scheme.]domain_name
  [ AS ] type [ DEFAULT default_value ] [ NOT NULL ] [ integrity_constraint ] [ evaluation ]
evaluation ::= INITIALLY { IMMEDIATE | DEFERRED }

The CREATE DOMAIN statement creates a domain of the specified data type.

The maximum length of the domain name is 31 characters. Domains must have a unique name in the specified schema. If the domain name already exists, the error sqlstate 40004 (KEY_DUPLICITY) occurs.

If you need more conditions in the integrity constraint (CHECK clause), connect the conditions using the AND or OR operators. Column values referenced in an integrity_constraint is set with the VALUE keyword. A domain for a positive integer number less than 1000 can be defined as follows:

CREATE DOMAIN Positive AS INT CHECK (VALUE > 0 AND VALUE < 1000)

Evaluation sets the time the integrity constraint will be checked. INITIALLY IMMEDIATE sets the check immediately after statement execution. INITIALLY DEFERRED postpones the check until the end of the transaction.

Domains are created with an interactive wizard in the 602SQL Client. You can view the SQL form of the actual design at any time.

Example

A string type domain of 12 characters in the CZ_ISO coding with the constraint that it must be at least 3 characters:

DOMAIN `char_min3` CHAR(12) COLLATE CSISTRING 
CHECK (CHAR_LENGTH(VALUE)>2) INITIALLY DEFERRED 

See