Saturday, July 23, 2011

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

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Deep's | Bloggerized by Deep - Deep's Templates | ElearSQL-Server