Jul 11, 2013

check constraint

7/11/2013 10:28:00 PM

check constraint

-it can be used limiting by values are accepted one more values.
-it can be used any logical values expression and true or false logical operators.
-CHECK constraints reject values that evaluate to FALSE. Because null values the Database Engine inserts NULL and does not return an error.

Check Constraint:


 CREATE TABLE Test(Id int  constraint Ck_ID check (LEN(ID)=1))

 INSERT INTO Test values(null)

 (1 row(s) affected)

 

 Function Using Check Constraint:


 CREATE TABLE Test2 (ID1 int, ID2 int);

 CREATE FUNCTION CheckingFun()
 RETURNS int
 AS
 BEGIN
 DECLARE @val int
 SELECT  @val=COUNT(*) from Test2
 RETURN  @val
 END;

 ALTER TABLE Test2 ADD CONSTRAINT CH_ID CHECK(dbo.CheckingFun()>=1)

 INSERT INTO Test2 Values(10,10)

 (1 row(s) affected)

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

Recent Posts
Popular Articles

 

© 2013 MUNISH ORACLE DBA& .Net Developer. All rights resevered. Designed by Templateism

Back To Top