FirebirdSQL logo

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.

ALTER DOMAIN clauses

TO name

Renames the domain, as long as there are no dependencies on the domain, i.e. table columns, local variables or procedure arguments referencing it.

SET DEFAULT

Sets a new default value for the domain, replacing any existing default.

DROP DEFAULT

Deletes a previously specified default value and replace it with NULL.

SET NOT NULL

Adds a NOT NULL constraint to the domain;columns or parameters of this domain will be prevented from being written as NULL, i.e. a value is required.

Note

Adding a NOT NULL constraint to an existing domain will subject all columns using this domain to a full data validation, so ensure that the columns have no nulls before attempting the change.

DROP NOT NULL

Drops the NOT NULL constraint from the domain.

Note

An explicit NOT NULL constraint on a column that depends on a domain prevails over the domain.In this situation, the modification of the domain to make it nullable does not propagate to the column.

ADD CONSTRAINT CHECK

Adds a CHECK constraint to the domain.If the domain already has a CHECK constraint, it has to be deleted first, using an ALTER DOMAIN statement that includes a DROP CONSTRAINT clause.

TYPE

Changes the data type of the domain to a different, compatible one.The system will forbid any change to the type that could result in data loss.An example would be if the number of characters in the new type were smaller than in the existing type.

Important

When you alter the attributes of a domain, existing PSQL code may become invalid.For information on how to detect it, read the piece entitled The RDB$VALID_BLR Field in Appendix A.