CREATE TABLE user1
(
id INT IDENTITY(1, 1),
name1 VARCHAR(20),
salary INT CONSTRAINT chk_sal CHECK (salary>2000)
--adding first check condition to filter database sal should be 2000
)
--entering data
INSERT INTO user1
VALUES ('Rambo',
23000)
INSERT INTO user1
VALUES ('John',
8000)
SELECT *
FROM user1
--Now what if we want to make changed into our check condition without effecting old data how it can be done
--1.Drop Existing Constraint
ALTER TABLE user1 DROP CONSTRAINT chk_sal
--2,Now add constraint again
ALTER TABLE user1 WITH NOCHECK ADD CONSTRAINT chk_sal CHECK(salary>9000)
SELECT *
FROM user1
INSERT INTO user1
VALUES ('Vertigo',
10000)
Listen to Your Daily Tune's
Sunday, September 19, 2010
Check Constraint Sql Server 2005 Part-2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment