We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Tuesday, June 16, 2015

How To Create Check Constraints On Column In SQL SERVER

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 Allows Values For That Column.
We can also apply check constraints on multiple columns in the table.
There are some steps to know about the check constraint on the table column. Which is given below

Step1:- Create the check constraints on the column when a 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')

No comments: