Handling Referential Integrity

Downloads
44148.zip

If you have tables that are related to each other with foreign key constraints, running forced replication might disrupt the referential integrity of Subscribers if the forced-replication process doesn't update tables in the right order. For example, if you run UPDATE commands for several tables in one batch and the first replication stored procedure you run handles DELETE operations, the command might remove parent records on the Subscriber, which would violate foreign key constraints and generate an error message that would stop the replication process. To avoid such events, I recommend using the NOT FOR REPLICATION option for each foreign key you create on tables that participate in replication. This option means that SQL Server won't check the foreign key constraint when replication inserts or deletes data on Subscribers. Listing A shows how to use the NOT FOR REPLICATION option. For information about how referential integrity works, see Kalen Delaney's July 2000 article "Referential Integrity in SQL Server," InstantDoc ID 8687.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.