Latest Post

Saturday, 24 September 2016

Check constraint in SQL server

Hello guys , I am sharing CHECK constraint with you.

CHECK constraints CHECK constraint is used to limiting the values that are accepted by one or more columns.

Following is the example to apply SQL CHECK Constraint on CREATE TABLE

CREATE TABLE Employee
(
Id int NOT NULL CHECK (Id>0),
Name varchar(255) NOT NULL,
Address varchar(255),
Age int,
)


Following is the example to apply SQL CHECK Constraint on ALTER TABLE

ALTER TABLE Employee
ADD CONSTRAINT chk_Employee CHECK (Id>0 AND age> 20)

Following is the example to DROP a CHECK Constraint

ALTER TABLE Employee

DROP CONSTRAINT chk_Employee

Government Jobs