Can i temporarily disable a foreign key constraint. How do i do this?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With