How can we help you today? How can we help you today?
JohnnyT
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