|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, April 10, 2013 8:38 AM
Points: 1,419,
Visits: 420
|
|
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?
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, April 10, 2013 8:38 AM
Points: 1,419,
Visits: 420
|
|
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
|
|
|
|