title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | helpviewer_keywords | monikerRange | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Disable check constraints with INSERT and UPDATE statements |
Disable Check Constraints with INSERT and UPDATE Statements |
WilliamDAssafMSFT |
wiassaf |
11/24/2021 |
sql |
table-view-index |
how-to |
|
>=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current||=fabric |
[!INCLUDE sqlserver2016-asdb-asdbmi-asa-pdw-fabricsqldb]
You can disable a check constraint for INSERT
and UPDATE
transactions in [!INCLUDEssnoversion] by using [!INCLUDEssManStudioFull] or [!INCLUDEtsql]. After you disable the check constraints, future inserts or updates to the column will not be validated against the constraint conditions. Use this option if you know that new data will violate the existing constraint or if the constraint applies only to the data already in the database.
For more information, see Check Constraints.
Note
Check constraints are enabled and disabled with an ALTER TABLE
statement, which always requires a schema modification lock (Sch-M
). Sch-M locks prevent concurrent access to the table. For more information, see Locks and ALTER TABLE.
Requires ALTER permission on the table.
-
In Object Explorer, expand the table with the constraint and then expand the Constraints folder.
-
Right-click the constraint and select Modify.
-
In the grid under Table Designer, click Enforce For INSERTs And UPDATEs and select No from the drop-down menu.
-
Click Close.
-
In Object Explorer, connect to an instance of [!INCLUDEssDE].
-
On the Standard bar, click New Query.
-
Copy and paste the following examples into the query window and click Execute.
USE AdventureWorks2022; GO ALTER TABLE Purchasing.PurchaseOrderHeader NOCHECK CONSTRAINT CK_PurchaseOrderHeader_Freight; GO