How can we help you today? How can we help you today?
JohnnyT

Activity overview

Latest activity by JohnnyT

Found new bug when using "Add object existence check" option
We very rarely drop columns from our database, but we just had a case where we received an error in a generated SQL Compare script when dropping a column that did not have the default object proper...
2 followers 6 comments 0 votes
After a little more research, I found the bug. The deployment script does try to disable enforcement of the FK constraint, but the logic added by the "Add object existence checks" is incorrect. Here's an example. I have two tables named "items" and "cartrule" which have an unenforced relation defined in it. With this option checked, the deployment script drops the constraint... PRINT N'Dropping foreign keys from [dbo].[cartrule]' GO IF EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_cartrule_items]', 'F') AND parent_object_id = OBJECT_ID(N'[dbo].[cartrule]', 'U')) ALTER TABLE [dbo].[cartrule] DROP CONSTRAINT[FK_cartrule_items] GO Then it rebuilds it... PRINT N'Adding foreign keys to [dbo].[cartrule]' GO IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_cartrule_items]', 'F') AND parent_object_id = OBJECT_ID(N'[dbo].[cartrule]', 'U')) ALTER TABLE [dbo].[cartrule] WITH NOCHECK ADD CONSTRAINT [FK_cartrule_items] FOREIGN KEY ([department], [category], [item]) REFERENCES [dbo].[items] ([department], [category], [item]) NOT FOR REPLICATION GO Then it attempts to mark it as unenforced... PRINT N'Disabling constraints on [dbo].[cartrule]' GO IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_cartrule_items]', 'F') AND parent_object_id = OBJECT_ID(N'[dbo].[cartrule]', 'U')) ALTER TABLE [dbo].[cartrule] NOCHECK CONSTRAINT [FK_cartrule_items] GO However, the logic added by the "Add object existence checks" option is not correct. It should be "IF EXISTS", not "IF NOT EXISTS". The way it is now, it remains enforced. Thanks. / comments
After a little more research, I found the bug. The deployment script does try to disable enforcement of the FK constraint, but the logic added by the "Add object existence checks" is incorrect. H...
0 votes
New bug in comparing Foreign Key Relationships
Thank you for adding the "Use DROP and CREATE instead of ALTER" option that we requested. This will be a big help when deploying update scripts to clients who may already have pre-release versions...
3 followers 8 comments 0 votes