SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Deploy does not detect check constraint changes


Deploy does not detect check constraint changes

Author
Message
Øystein Fallo
Øystein Fallo
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1469 Visits: 454
I am using SQL Server database project in VS 2010, and am experiencing a weird behavior related to check constraints.
I have a table, with 3 columns. For simplicity lets call them column_1, column_2 and column_3.
Then I have a check constraint like this:

ALTER TABLE [dbo].[Table1] ADD CONSTRAINT [CheckConstraint1]
CHECK (column_1 is not null and column_2 is not null or column_1 is not null and column_3 is not null)



Deploy to database, and everything looks good.
Then I change the constraint by adding some parentheses to this:

ALTER TABLE [dbo].[Table1] ADD CONSTRAINT [CheckConstraint1]
CHECK ((column_1 is not null and column_2 is not null) or (column_1 is not null and column_3 is not null))




This is obviously quite a different check constraint, but deploy does not seem to catch this change.
Anyone got any suggestions?
Øystein Fallo
Øystein Fallo
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1469 Visits: 454
Ok, so I forgot that OR and AND have different operator precedence, so the two constraints are effectively the same.
Since I usually always put parentheses for readability - this slipped my mind Hehe
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search