CHECK constraint is used to give a limit for the values to be passed on the column.
Data is inserted on the column according to the condition on which the CHECK constraint is given. A check constraint is used in SQL server allow you to specify condition on each row in a table.
CHECK constraints are column-level (single column) and table-level (multiple columns).
Check constraint is create two times, first when database table is created and other is alter table in exists table in database
1- SQL Check Constraint on table create:
The following SQL creates a Check constraint on the 'Age' column when the 'Student' table is created. The Check constraint ensures that the age of a Student must be 18, or older:
create table Student(
stuID int not null primary key,
stuName varchar(255),
stuCourse varchar(255),
stuAge int CHECK (stuAge>=18) );
Check constraint on multiple columns in a table
create table StudentRecord(
stuID int not null primary key,
stuName varchar(255),
stuCourse varchar(255),
stuAge int ,
stuMarks int ,
CONSTRAINT chk_StudentRecord CHECK (stuAge>=18 AND stuMarks>=40) );
2- SQL Check Constraint on created table:
The following SQL creates a Check Constraint on student Age in “Student” table which is created in database. Here the Check Constraint is used with SQL ALTER command. Ex- for single column in table,
ALTER TABLE Student
ADD CHECK (stuAge>=18);
For multiple columns of a table,
ALTER TABLE StudentRecord
ADD CONSTRAINT chk_Students CHECK (stuAge>=18 AND stuMarks>=40);
In the above Student table the records entered in which stuAge must be 18 or above and stuID is more than 3.
Drop Check Constraint:
To Drop a created Check Constraint in table, use the following SQL statement,
ALTER TABLE Student
DROP CONSTRAINT chk_Student;
Other one is-
alter table StudentRecord
drop constraint chk_StudentRecord;
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
SQL Check Constraint:
CHECK constraint is used to give a limit for the values to be passed on the column.
Data is inserted on the column according to the condition on which the CHECK constraint is given. A check constraint is used in SQL server allow you to specify condition on each row in a table.
CHECK constraints are column-level (single column) and table-level (multiple columns).
Check constraint is create two times, first when database table is created and other is alter table in exists table in database
1- SQL Check Constraint on table create:
The following SQL creates a Check constraint on the 'Age' column when the 'Student' table is created. The Check constraint ensures that the age of a Student must be 18, or older:
Check constraint on multiple columns in a table
2- SQL Check Constraint on created table:
The following SQL creates a Check Constraint on student Age in “Student” table which is created in database. Here the Check Constraint is used with SQL ALTER command. Ex- for single column in table,
For multiple columns of a table,
In the above Student table the records entered in which stuAge must be 18 or above and stuID is more than 3.
Drop Check Constraint:
To Drop a created Check Constraint in table, use the following SQL statement,
Other one is-