Sql Query To use CHECK Constraint


CHECK Constraint is used, when we want to limit the value range that is going to be inserted in a column.

For example, Suppose we want that the data of employee should be inserted whose age is greater than 20.

Then the CHECK constraint will check, whether the age is greater than 20 or not. If not, then the data will not be inserted.

SQL Query
create table user_detail ( id int, first_name varchar(50), age int CHECK(age>20) ); INSERT INTO user_detail VALUES (1,'Sam',18);
Output