Loading lesson path
Concept visual
Start at both ends
❮ SQL Keywords
constraint limits the value that can be placed in a column.
The following SQL creates a CHECK constraint on the "Age" column when the "Persons" table is created. The CHECK constraint ensures that you can not have any person below 18 years:
( Age int, CHECK (Age>=18)
);Formula
SQL Server / Oracle / MS Access:( Age int CHECK (Age>=18)
);To allow naming of a CHECK constraint, and for defining a CHECK constraint on multiple columns, use the following SQL syntax:
Formula
MySQL / SQL Server / Oracle / MS Access:( Age int, City varchar(255), CONSTRAINT CHK_Person CHECK (Age>=18 AND City='Sandnes')
);To create a CHECK constraint on the "Age" column when the table is already created, use the following SQL:
Formula
MySQL / SQL Server / Oracle / MS Access:ADD CHECK (Age>=18);To allow naming of a CHECK constraint, and for defining a CHECK constraint on multiple columns, use the following SQL syntax:
Formula
MySQL / SQL Server / Oracle / MS Access:ADD CONSTRAINT CHK_PersonAge CHECK (Age>=18 AND City='Sandnes');To drop a CHECK constraint, use the following SQL:
Formula
SQL Server / Oracle / MS Access:DROP CONSTRAINT CHK_PersonAge;DROP CHECK CHK_PersonAge;❮ SQL Keywords