Skip to main content

That part of declarative referential integrity (DRI) where a column's permitted range of values is enforced by a Boolean predicate.

SQL allows for a column to have a CHECK constraint defined. This, quite literally, checks the value about to be written to that column. The constraint is defined as a predicate which evaluates to TRUE, FALSE or UNKNOWN. When the predicate evaluates to TRUE or UNKNOWN the value will be written; evaluation to FALSE will cause the write to fail.

Typical use is to limit a column's domain further than the data type alone can do. For example, column WEIGHT may be defined as an integer. It should not contain negative values, however. This could be enforced by a CHECK constraint

create table ..
(
    weight int CONSTRAINT positive_weight CHECK (weight > 0)
...
)

Attempts to write a WEIGHT of zero or less will now fail.