Udostępnij za pośrednictwem


Disable Foreign Key Constraints for Replication

You can disable foreign key constraints for replication in SQL Server 2012 by using SQL Server Management Studio or Transact-SQL. This can be useful if you are publishing data from a previous version of SQL Server.

[!UWAGA]

If a table is published using replication, foreign key constraints are automatically disabled for operations performed by replication agents. When a replication agent performs an insert, update, or delete at a Subscriber, the constraint is not checked; if a user performs an insert, update, or delete, the constraint is checked. 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.

In This Topic

  • Before you begin:

    Security

  • To disable a foreign key constraint for replication, using:

    SQL Server Management Studio

    Transact-SQL

Before You Begin

Security

Permissions

Requires ALTER permission on the table.

Ikona strzałki używana z łączem Powrót na górę strony[Top]

Using SQL Server Management Studio

To disable a foreign key constraint for replication

  1. In Object Explorer, expand the table with the foreign key constraint you want to modify, and then expand the Keys folder.

  2. Right-click the foreign key constraint and then click Modify.

  3. In the Foreign Key Relationships dialog box, select a value of No for Enforce For Replication.

  4. Click Close.

Ikona strzałki używana z łączem Powrót na górę strony[Top]

Using Transact-SQL

To disable a foreign key constraint for replication

  • To perform this task in Transact-SQL, drop the foreign key constraint. Then add a new foreign key constraint and specify the NOT FOR REPLICATION option.

For more information, see ALTER TABLE (Transact-SQL).

Ikona strzałki używana z łączem Powrót na górę strony[Top]