Disable Foreign Key Constraint Example
To disable a foreign key constraint, use the command alter table with NOCHECK constraint.
Status Foreign Key
select name, type_desc, is_disabled from sys.foreign_keys;
name | type_desc | is_disabled |
---|---|---|
FK_DEPT_ID | FOREIGN_KEY_CONSTRAINT | 0 |
Disable Foreign Key Constraint
USE tempdb;
GO
ALTER TABLE dbo.EMPLOYEES
NOCHECK CONSTRAINT FK_DEPT_ID;
GO
Status Foreign Key
select
name, type_desc, is_disabled
from sys.foreign_keys;
name | type_desc | is_disabled |
---|---|---|
FK_DEPT_ID | FOREIGN_KEY_CONSTRAINT | 1 |