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


Schema Compare and Foreign Keys Created WITH NOCHECK


Schema Compare and Foreign Keys Created WITH NOCHECK

Author
Message
Ringo-394296
Ringo-394296
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 85
Hi All,

We're trying to create a schema synchronization script by comparing a database project in Visual Studio/TFS (source) to a deployed database (destination). The script produced will be used to bring the populated destination database inline with the code checked into Visual Studio/TFS.

In TFS foreign keys are defined in the form:

ALTER TABLE [dbo].[foo]
ADD CONSTRAINT [FK_Foo_Bar] WITH NOCHECK

FOREIGN KEY ([Bar_Id]) REFERENCES [Dbo].[Bar] ([Bar_Id])
ON DELETE NO ACTION ON UPDATE NO ACTION;


In the destination database all foreign keys are inactive and marked as untrusted and the underlying data violates the key's logic, i.e. if we were to try and re-enable the foreign keys with CHECK CHECK, it would fail. For info. the only reason that we have the foreign keys in this database is to enable any design tool to show data relationships, we actively do not want the FKs to enforce integrity for operational/performance reasons.

When we compare the schema, a difference is picked up between the foreign keys and the source foreign key looks like:

ALTER TABLE [dbo].[foo]
ADD CONSTRAINT [FK_Foo_Bar]

FOREIGN KEY ([Bar_Id]) REFERENCES [Dbo].[Bar] ([Bar_Id])
ON DELETE NO ACTION ON UPDATE NO ACTION;


So the schema comparison tool is stripping off/ignoring the WITH NOCHECK clause and attempting to create the foreign key as active, which causes the script to fail when run over the database (due to the data not adhering to it as described above).

Does anyone know of a setting which controls the behavior of scripting FKs, i.e. ignoring this option in the key's script or setting a default of active/inactive at the sync level? Or indeed any information regarding this behavior at all would be very useful?

Thanks in advance

Our environment is as follows:
Destination database is on a SQL Server 2008 Enterprise (Build 10.0.2531.0) server and we're using Visual Studio 2008, 9.0.30729.1.
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