Disable foreign key constraint on table?

Can I temporarily disable a foreign key constraint. How to do it?

+6
sql sql-server sql-server-2005
source share
2 answers

To temporarily disable a constraint (foreign keys are constraints):

ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint 

To enable the restriction again

 ALTER TABLE MyTable CHECK CONSTRAINT MyConstraint 
+24
source share

By the way, that’s why you need Alter table permissions when you are BCP or Bulk Insert into a table. Using the default configuration, check the restrictions and foreign keys are not checked.

+1
source share

All Articles