Can i temporaryly disable a foreign key constraint. How do i do this?
+6
A:
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
Chris Shaffer
2009-04-08 01:59:15
be warned this will fail if your data is not referntially in tact.
ojblass
2009-04-08 02:04:28
+1
A:
Check also this related question:
Can foreign key constraints be temporarily disabled using TSQL?
kristof
2009-04-08 07:58:51
A:
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.
Andy Jones
2009-04-08 12:53:11