SQL Compare 10 does not correctly report CHECK CONSTRAINT
mdesousa
Posts: 15
I'm testing a trial of SQL Compare 10.1, and ran into an issue when the "NOCHECK" flag of our constraints is compared... it looks like SQL Compare doesn't accurately reflect the status of the flag.
To reproduce, create a database with some tables and some foreign key constraints.
Take a snapshot of the database.
When I run SQL Compare at this point, no differences are reported.
Then run this command:
alter table <SomeTable> nocheck constraint <SomeConstraint>
Run a comparison... SQL Compare shows the NoCheck flag.
Now run this command to re-enable the check:
alter table <SomeTable> check constraint <SomeConstraint>
At this point, SQL Compare still shows the NOCHECK flag, which is wrong.
Has anyone else run into this problem?
To reproduce, create a database with some tables and some foreign key constraints.
Take a snapshot of the database.
When I run SQL Compare at this point, no differences are reported.
Then run this command:
alter table <SomeTable> nocheck constraint <SomeConstraint>
Run a comparison... SQL Compare shows the NoCheck flag.
Now run this command to re-enable the check:
alter table <SomeTable> check constraint <SomeConstraint>
At this point, SQL Compare still shows the NOCHECK flag, which is wrong.
Has anyone else run into this problem?
Comments
before: After:
So I think the result is not as you expect because the original constrint definition remains (WITH NOCHECK in this context means the existing data will not be checked) and the additional NOCHECK CONSTRAINT is added to disable the constraint. These two bits of syntax, although they look very similar, fulfill two different functions.
In my example, I was referring exclusively to the second scenario. So, assuming that my table already has all its constraints and they were enabled when they were initially created. I am taking a snapshot of the database and then running this command:
ALTER TABLE [dbo].[SystemSW] NOCHECK CONSTRAINT [FK_SystemSW_Software]
If I run SQL Compare at this point, there is a difference between the snapshot and the live database, which is expected.
Next, I run this command:
ALTER TABLE [dbo].[SystemSW] CHECK CONSTRAINT [FK_SystemSW_Software]
I would expect SQL Compare to show no differences... but it actually still shows that the NOCHECK flag is enabled.
I see. It looks to be broken in 10.1. It worked in 10.0. I'll see what I can find out.
ALTER TABLE [dbo].[SystemSW] CHECK CHECK CONSTRAINT [FK_SystemSW_Software]
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'CHECK'.
ALTER TABLE tablename WITH CHECK CHECK CONSTRAINT constraintName
Thank you.