SQL > Constraint > CHECK Constraint

The CHECK constraint ensures that all values in a column satisfy certain conditions. Once defined, the database will only insert a new row or update an existing row if the new value satisfies the CHECK constraint. The CHECK constraint is used to ensure data quality.

The SQL CHECK constraint enforces a Boolean condition on column values at insert/update time, rejecting any data that fails the rule and keeping your table clean and consistent.

For example, in the following CREATE TABLE statement,

CREATE TABLE Customer
(SID integer CHECK (SID > 0),
Last_Name varchar (30),
First_Name varchar(30));

Column "SID" has a constraint -- its value must only include integers greater than 0. So, attempting to execute the following statement,

INSERT INTO Customer VALUES (-3, 'Gonzales', 'Lynn');

will result in an error because the values for SID must be greater than 0.

Please note that the CHECK constraint does not get enforced by MySQL at this time.

Frequently Asked Questions

Q: What does the SQL CHECK constraint do?
A: The CHECK constraint ensures that all values inserted or updated in a column satisfy a specified condition. If the condition is violated, the database rejects the operation.

Q: Does MySQL enforce the CHECK constraint?
A: No. MySQL parses but does not enforce the CHECK constraint. You must use a trigger or application-level validation if you need enforcement in MySQL.

Q: Can a CHECK constraint reference multiple columns?
A: Yes. A table-level CHECK constraint can reference multiple columns in the same table, allowing cross-column validation rules.

Q: How is CHECK different from NOT NULL?
A: NOT NULL simply prevents NULL values, while CHECK lets you define any Boolean condition — for example, requiring a numeric column to be greater than zero.

Next: SQL Primary Key

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact