Sunday, 9 October 2011

SQL Constraints- check

nThe CHECK constraint is used to limit the value range that can be placed in a column.
nIf you define a CHECK constraint on a single column it allows only certain values for this column.
Create-Check
CREATE TABLE EMPtbl1( (EMPID int NOT NULL, EMPname varchar(255) NOT NULL,
company varchar(255),salary varchar(255),City varchar(255),CONSTRAINT chk_EMPtbl1 CHECK (EMPID>0, Location=‘Bangalore’))
Alter-Check
ALTER TABLE EMPtbl1
ADD CONSTRAINT Chk_EMPtbl1 CHECK (EMPID>0, Location=‘Bangalore’))
Drop-Check
ALTER TABLE EMPtbl1
DROP CONSTRAINT chk_EMPtbl1

No comments:

Post a Comment