Udostępnij za pośrednictwem


Disable Check Constraints for Replication

You can disable check constraints in SQL Server 2012 by using SQL Server Management Studio or Transact-SQL. You can also explicitly disable check constraints for replication, which can be useful if you are publishing data from a previous version of SQL Server.

[!UWAGA]

If a table is published using replication, check 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. For more information, see Specify Schema Options (SQL Server Management Studio).

In This Topic

  • Before you begin:

    Security

  • To disable a check 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 check constraint for replication

  1. In Object Explorer, expand the table with the check constraint you want to modify, and then expand the Constraints folder.

  2. Right-click the check constraint you wish to modify and then click Modify.

  3. In the Check Constraints dialog box, under Table Designer, 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 check constraint for replication

  1. In Object Explorer, connect to an instance of Database Engine.

  2. On the Standard bar, click New Query.

  3. Copy and paste the following example into the query window and click Execute. The example creates a table with an IDENTITY column and a CHECK constraint on the table. The example then drops the constraint and recreates it specifying the NOT FOR REPLICATION clause.

    USE AdventureWorks2012;
    GO
    CREATE TABLE dbo.doc_exd (column_a int IDENTITY (1,1) 
    CONSTRAINT exd_check CHECK (column_a > 1)) 
    
    ALTER TABLE dbo.doc_exd 
    DROP CONSTRAINT exd_check; 
    GO
    ALTER TABLE dbo.doc_exd  
    ADD CONSTRAINT exd_check CHECK NOT FOR REPLICATION (column_a > 1);
    

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

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

Zobacz także

Inne zasoby

Specify Schema Options (SQL Server Management Studio)