T-SQL Tutorial

Disable Foreign Key T-SQL


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;

nametype_descis_disabled
FK_DEPT_IDFOREIGN_KEY_CONSTRAINT0



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;

nametype_descis_disabled
FK_DEPT_IDFOREIGN_KEY_CONSTRAINT1