FirebirdSQL logo

Domain Override

While defining a column using a domain, it is possible to override some attributes inherited from the domain.[fblangref50-dtyp-tbl-domoverride] summarises the rules for domain override.

Table 1. Rules for Overriding Domain Attributes in Column Definition
Attribute Override? Comments

Data type

No

 

Default value

Yes

 

Text character set

Yes

It can also be used to restore the default database values for the column

Text collation

Yes

 

CHECK constraints

Yes

To add new conditions to the check, you can use the corresponding CHECK clauses in the CREATE and ALTER statements at the table level.

NOT NULL

No

Often it is better to leave domain nullable in its definition and decide whether to make it NOT NULL when using the domain to define columns.

Creating and Administering Domains

A domain is created with the DDL statement CREATE DOMAIN.

Short Syntax
CREATE DOMAIN name [AS] <type>
  [DEFAULT {<literal> | NULL | <context_var>}]
  [NOT NULL] [CHECK (<condition>)]
  [COLLATE <collation>]
See also

CREATE DOMAIN in the Data Definition (DDL) Statements chapter.

Altering a Domain

To change the attributes of a domain, use the DDL statement ALTER DOMAIN.With this statement you can:

  • rename the domain

  • change the data type

  • drop the current default value

  • set a new default value

  • drop the NOT NULL constraint

  • set the NOT NULL constraint

  • drop an existing CHECK constraint

  • add a new CHECK constraint

Short Syntax
ALTER DOMAIN name
  [{TO new_name}]
  [{SET DEFAULT { <literal> | NULL | <context_var> } |
    DROP DEFAULT}]
  [{SET | DROP} NOT NULL ]
  [{ADD [CONSTRAINT] CHECK (<dom_condition>) |
    DROP CONSTRAINT}]
  [{TYPE <datatype>}]
Example
ALTER DOMAIN STORE_GRP SET DEFAULT -1;

When changing a domain, its dependencies must be taken into account: whether there are table columns, any variables, input and/or output parameters with the type of this domain declared in the PSQL code.If you change domains in haste, without carefully checking them, your code may stop working!

Important

When you convert data types in a domain, you must not perform any conversions that may result in data loss.Also, for example, if you convert VARCHAR to INTEGER, check carefully that all data using this domain can be successfully converted.

See also

ALTER DOMAIN in the Data Definition (DDL) Statements chapter.

Deleting (Dropping) a Domain

The DDL statement DROP DOMAIN deletes a domain from the database, provided it is not in use by any other database objects.

Syntax
DROP DOMAIN name
Example
DROP DOMAIN Test_Domain
See also

DROP DOMAIN in the Data Definition (DDL) Statements chapter.