Easy Tutorial
❮ Sql Unique Func Extract ❯

SQL CHECK Constraint


SQL CHECK Constraint

The CHECK constraint is used to limit the value range in a column.

If a CHECK constraint is defined on a single column, it allows only certain values for this column.

If a CHECK constraint is defined on a table, it restricts the values in certain columns based on the values in other columns in the row.


SQL CHECK Constraint When Creating a Table

The following SQL creates a CHECK constraint on the "P_Id" column when the "Persons" table is created. The CHECK constraint specifies that the "P_Id" column must only contain integers greater than 0.

MySQL:

SQL Server / Oracle / MS Access:

To name a CHECK constraint and define a CHECK constraint on multiple columns, use the following SQL syntax:

MySQL / SQL Server / Oracle / MS Access:


SQL CHECK Constraint When Altering a Table

If a table has already been created, to create a CHECK constraint on the "P_Id" column, use the following SQL:

MySQL / SQL Server / Oracle / MS Access:

To name a CHECK constraint and define a CHECK constraint on multiple columns, use the following SQL syntax:

MySQL / SQL Server / Oracle / MS Access:


Dropping a CHECK Constraint

To drop a CHECK constraint, use the following SQL:

SQL Server / Oracle / MS Access:

MySQL:

❮ Sql Unique Func Extract ❯