How to disable foreign key in sql server

If you want to disable foreign key to do updates in a table, here are the steps

1. Disable all the foreign keys by using,

ALTER TABLE TABLE_NAME NOCHECK CONSTRAINT ALL

or

ALTER TABLE TABLE_NAME NOCHECK CONSTRAINT CONSTRAINT_NAME

2. Update the key values

2. Enforce the keys again to work like charm.

Leave a comment