A CONSTRAINT definition defines an integrity condition (restrictions for column values, see
data integrity) that must be fulfilled by all the rows in one table.Syntax
<constraint_definition> ::= CHECK <search_condition>
| CONSTRAINT <search_condition>
| CONSTRAINT <constraint_name> CHECK <search_condition>
Simple constraint (for one column), model table
customertitle CHAR (7) CONSTRAINT title IN ('Mr', 'Mrs', 'Comp')
Complex constraint (for several columns), model table
reservationarrival DATE NOT NULL
departure DATE CONSTRAINT departure > arrival
The system checks whether the arrival is before the departure.
Explanation
A CONSTRAINT definition defines an integrity condition that must be fulfilled by all the column values in the columns defined by the
column definition with CONSTRAINT definition.The CONSTRAINT definition in a column is checked when a row is inserted and a column changed that occurs in the CONSTRAINT definition. If the CONSTRAINT definition is violated, the INSERT or UPDATE statement fails.
When you define a constraint, you specify implicitly that the NULL value is not permitted as an input.
The search condition (
search_condition) of the CONSTRAINT definition must not contain a subquery.The search condition of the CONSTRAINT definition must only contain column names in the form
<column name>.Constraint name
Number of columns in a search condition