


The range of values of a column's data type can be restricted further by using so-called constraints. There is a distinction between simple and complex constraints.
Simple constraints are conditions that only refer to the one column to be defined.
An upper and lower bound for the values to be entered can be defined, for example, using BETWEEN <lower bound> AND <upper bound>. The IN predicate allows the valid values to be listed.
cno FIXED (4) CONSTRAINT cno BETWEEN 1 AND 9999
title CHAR (5) CONSTRAINT title IN ('Mr', 'Mrs', 'Comp')
account FIXED (7,2) CONSTRAINT account > -10000 AND
account < 10000
Specifying NOT NULL has the effect that a column must be provided with a value. Such a column is called a mandatory column. Without a NOT NULL specification, the column is optional. A constraint defined for a column implicitly means that the NULL value cannot be entered.
Complex constraints are those referring to more columns.
In a table 'reservation', for example, where the days of arrival and departure are stored, it could be useful to check whether the arrival is before the departure.
arrival DATE NOT NULL
departure DATE CONSTRAINT departure > arrival
This condition can be extended at will:
departure DATE CONSTRAINT departure > arrival
AND departure < '12/31/1997'
Except for very few conditions, everything that could also be a valid search condition can be formulated in a CONSTRAINT definition. In principle, any number of columns can be addressed. But it should be taken into account that the additional checks performed in the case that modifications have been made to this table decrease the system performance. Several conditions can be connected with the operators AND, OR, and NOT.


