Click here to Skip to main content
15,914,943 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Check constraints are used for validation while insertion.
My question is "Do they validate data while updating data" ?
if answer is No, Then is there anything else which can help out ?
Posted
Comments
Maciej Los 28-May-13 11:54am    
I'm not sure i understand you well, but ff constraints are used for "validation" while insertion, why do they can't be used for "validation" while updating? Of course, they can.
What kind of situation do you have? What do you want to achieve using constraints?
gvprabu 28-May-13 11:58am    
What you tried.... It will work for UPDATE also....

1 solution

The easiest way to determine this would have been to try it out yourself with a sample table - e.g. the one at http://msdn.microsoft.com/en-us/library/ms188258(v=sql.105).aspx[^]

I added a constraint to that table
ADD CONSTRAINT colx CHECK (col1 >= 1 )

and then tried
SQL
INSERT INTO CheckTbl VALUES (10, 10)
update CheckTbl SET col1 = -1 where col2 = 10

which gives you
Msg 547, Level 16, State 0, Line 1
UPDATE statement conflicted with COLUMN CHECK constraint 'colx'. The conflict occurred in database 'master', table 'CheckTbl', column 'col1'.
The statement has been terminated.
(0 row(s) affected)


So your answer is "Yes"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900