Can i temporarily disable a foreign key constraint. How do i do this?
2 Answers
To temporarily disable a constraint (foreign keys are constraints):
ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint
To re-enable a constraint
ALTER TABLE MyTable CHECK CONSTRAINT MyConstraint
1 Comment
ojblass
be warned this will fail if your data is not referntially in tact.
Incidentally, this is why you need "Alter table" permissions when you BCP or Bulk Insert data into a table. Using the default configuration, check constraints and foreign keys are not checked.