How Do You Stop a Foreign Key Constraint

SET FOREIGN_KEY_CHECKS=0;SET FOREIGN_KEY_CHECKS=1;ALTER TABLE table_name DISABLE KEYS;ALTER TABLE table_name ENABLE KEYS;ALTER TABLE table_name1 DROP FOREIGN KEY fk_name1; ALTER TABLE table_name2 DROP FOREIGN KEY fk_name2;

How do I disable foreign key constraints?

  1. In Object Explorer, expand the table with the constraint and then expand the Keys folder.
  2. Right-click the constraint and select Modify.
  3. In the grid under Table Designer, select Enforce Foreign Key Constraint and select No from the drop-down menu.

Can we disable foreign key constraint in SQL Server?

To disable a foreign key constraint, use the NOCHECK argument within an ALTER TABLE statement. Like this: ALTER TABLE BandMember NOCHECK CONSTRAINT FK_BandMember_Musician; This code disables a foreign key constraint called FK_BandMember_Musician .

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest