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.

For example, in the following CREATE TABLE statement,

(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.

Next: SQL Primary Key

Learn From Udemy: SQL For Data Science With Google Big Query icon

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