We recommend using Visual Studio 2017

How to: Disable Foreign Key Constraints for Replication

If you publish a table by using replication, you automatically disable foreign key constraints for operations that replication agents perform. The constraint is still checked when a user performs an insert, update, or delete operation but not when a replication agent performs one at a Subscriber. The constraint is disabled for the replication agent because the constraint was already checked at the Publisher when the data was originally inserted, updated, or deleted. For more information, see "Controlling Constraints, Identities, and Triggers with NOT FOR REPLICATION" on the Microsoft Web site.

You can also explicitly disable foreign key constraints for replication, which can be useful if you are publishing data from a previous version of SQL Server.

NoteNote

A new version of Table Designer appears for databases in the SQL Server 2012 format. This topic describes the old version of Table Designer, which you use with databases in earlier formats of SQL Server.

In the new version, you can change a table definition through a graphical interface or directly in a script pane. If you use the graphical interface, the table’s definition is automatically updated in the script pane. To apply the SQL code in the script pane, choose the Update button. For more information about the new version, see How to: Create Database Objects Using Table Designer.

NoteNote

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.

To disable a foreign key constraint for replication

  1. In Server Explorer, select the table with the constraint, and from the Database menu click Open Table Definition.

    The table opens in Table Designer.

  2. From the Table Designer menu, click Relationships.

  3. In the Foreign Key Relationships dialog box, select the relationship in the Selected Relationship list.

  4. In the grid, click Enforce For Replication, and in the box to the right choose No from the drop-down list box.

Show: