How to Create Check Constraints on Column in SQL SERVER 2008

By
The check constraint is  used for Domain integrity.It is used to insert the limited value in particular column.If we define a check constraint on a single column then it allow values for that column.
We can also apply check constraint on multiple column in the table.
There are some steps to know about check constraint on the table column.Which is given below

Step1:- Create the check constraints on the column when new table is creating.
create table student (id int,name char(20),city char(30) constraint chk check ( city  in ('delhi','ghaziabad','pune')))
Step2:- Create the check constraints on the  existing table's column .
alter table student add constraint chk1 check ( city  in ('delhi','ghaziabad', 'hydrabad'))

Step3:-  Create the multiple check constraints on the new table column.
create table student2 (id int,name char(20),city char(30) constraint chk check ( id>=100 and city  in ('delhi','ghaziabad','pune')))

Step4:- Create the multiple  check constraints on the  existing table's column .
alter table student add constraint chk2 check (id>=100 and city  in ('delhi','ghaziabad', 'hydrabad'))

Step5:- Insert the data in student table.
insert into student values(100,'ram','delhi')



see it:-

I hope this helpful for you.
click below for download whole command.
   DOWNLOAD

0 comments:

Post a Comment

Powered by Blogger.