Skip to content

Enable or Disable All Foreign Keys on a Table

Two statements that disable or enable all foreign key constraints on a table at once.

Published Sep 13, 2009

The whole-table version of toggling foreign keys: two statements that disable or enable every FK constraint on a table at once. NOCHECK CONSTRAINT ALL turns them off without touching existing data; WITH CHECK CHECK CONSTRAINT ALL turns them back on and validates the rows.

ALTER TABLE [Table_Name] NOCHECK CONSTRAINT ALL --Disable all foreign keys.
ALTER TABLE [Table_Name] WITH CHECK CHECK CONSTRAINT ALL --Enable all foreign keys.
An unhandled error has occurred. Reload 🗙