Check Constraint

SQL Check Constraint

A SQL Check constraint enforce domain integrity by limiting the values that are accepted by one or more columns.
Multiple CHECK constraints can be created for a single column. Also you can create a single CHECK constraint to multiple columns by creating it at the table level.
CHECK constraints reject values that evaluate to FALSE.
A CHECK constraint returns TRUE when the condition it is checking is not FALSE for any row in the table.

Example

CREATE TABLE Training_Course
(
ID INT PRIMARY KEY,
NAME VARCHAR(250) NOT NULL,
DURATION INT,
PRICE INT
);

ALTER TABLE Training_Course 
ADD CONSTRAINT CHK_TC 
CHECK (DURATION > 4 and PRICE < 500 );

INSERT INTO Training_Course(ID, NAME, DURATION, PRICE) values(1,'SQL',5,200);
(1 row(s) affected)

INSERT INTO Training_Course(ID, NAME, DURATION, PRICE) values(2,'T-SQL',7,700);
The INSERT statement conflicted with the CHECK constraint "CHK_TC". 
The conflict occurred in database "model", table "dbo.Training_Course".

Drop Check Constraint

ALTER TABLE Training_Course
DROP CONSTRAINT CHK_TC;