FirebirdSQL logo

CHECK Constraint

The CHECK constraint defines the condition the values inserted in this column or row must satisfy.A condition is a logical expression (also called a predicate) that can return the TRUE, FALSE and UNKNOWN values.A condition is considered satisfied if the predicate returns TRUE or value UNKNOWN (equivalent to NULL).If the predicate returns FALSE, the value will not be accepted.This condition is used for inserting a new row into the table (the INSERT statement) and for updating the existing value of the table column (the UPDATE statement) and also for statements where one of these actions may take place (UPDATE OR INSERT, MERGE).

Important

A CHECK constraint on a domain-based column does not replace an existing CHECK condition on the domain, but becomes an addition to it.The Firebird engine has no way, during definition, to verify that the extra CHECK does not conflict with the existing one.

CHECK constraints — whether defined at table level or column level — refer to table columns by their names.The use of the keyword VALUE as a placeholder — as in domain CHECK constraints — is not valid in the context of defining constraints in a table.

Example

with two column-level constraints and one at table-level:

CREATE TABLE PLACES (
  ...
  LAT DECIMAL(9, 6) CHECK (ABS(LAT) <=  90),
  LON DECIMAL(9, 6) CHECK (ABS(LON) <= 180),
  ...
  CONSTRAINT CHK_POLES CHECK (ABS(LAT) < 90 OR LON = 0)
);

NOT NULL Constraint

In Firebird, columns are nullable by default.The NOT NULL constraint specifies that the column cannot take NULL in place of a value.

A NOT NULL constraint can only be defined as a column constraint, not as a table constraint.