FirebirdSQL logo
 SHADOWTABLE 

CREATE DOMAIN Examples

  1. Creating a domain that can take values greater than 1,000, with a default value of 10,000.

    CREATE DOMAIN CUSTNO AS
      INTEGER DEFAULT 10000
      CHECK (VALUE > 1000);
  2. Creating a domain that can take the values 'Yes' and 'No' in the default character set specified during the creation of the database.

    CREATE DOMAIN D_BOOLEAN AS
      CHAR(3) CHECK (VALUE IN ('Yes', 'No'));
  3. Creating a domain with the UTF8 character set and the UNICODE_CI_AI collation.

    CREATE DOMAIN FIRSTNAME AS
      VARCHAR(30) CHARACTER SET UTF8
      COLLATE UNICODE_CI_AI;
  4. Creating a domain of the DATE type that will not accept NULL and uses the current date as the default value.

    CREATE DOMAIN D_DATE AS
      DATE DEFAULT CURRENT_DATE
      NOT NULL;
  5. Creating a domain defined as an array of 2 elements of the NUMERIC(18, 3) type.The starting array index is 1.

    CREATE DOMAIN D_POINT AS
      NUMERIC(18, 3) [2];
    Note

    Domains defined over an array type may be used only to define table columns.You cannot use array domains to define local variables in PSQL modules.

  6. Creating a domain whose elements can be only country codes defined in the COUNTRY table.

    CREATE DOMAIN D_COUNTRYCODE AS CHAR(3)
      CHECK (EXISTS(SELECT * FROM COUNTRY
             WHERE COUNTRYCODE = VALUE));
    Note

    The example is given only to show the possibility of using predicates with queries in the domain test condition.It is not recommended to create this style of domain in practice unless the lookup table contains data that are never deleted.

ALTER DOMAIN

Alters the attributes of a domain or renames a domain

Available in

DSQL, ESQL

Syntax
ALTER DOMAIN domain_name
  [TO new_name]
  [TYPE <datatype>]
  [{SET DEFAULT {<literal> | NULL | <context_var>} | DROP DEFAULT}]
  [{SET | DROP} NOT NULL]
  [{ADD [CONSTRAINT] CHECK (<dom_condition>) | DROP CONSTRAINT}]

<datatype> ::=
   <scalar_datatype> | <blob_datatype>

<scalar_datatype> ::=
  !! See Scalar Data Types Syntax !!

<blob_datatype> ::=
  !! See BLOB Data Types Syntax !!

!! See also CREATE DOMAIN Syntax !!
Table 1. ALTER DOMAIN Statement Parameters
Parameter Description

new_name

New name for domain.The maximum length is 63 characters

literal

A literal value that is compatible with datatype

context_var

Any context variable whose type is compatible with datatype

The ALTER DOMAIN statement enables changes to the current attributes of a domain, including its name.You can make any number of domain alterations in one ALTER DOMAIN statement.