DBAtlas · Database operations atlas

1785: Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths

SQL Server

What does it mean?

The foreign key you are adding could create a cycle or multiple cascading delete/update paths to the same table in cascade (ON DELETE/UPDATE CASCADE) operations. SQL Server rejects it to avoid ambiguous cascade behavior.

Why does it happen?

An FK with a cascade action creating a circular reference between tables (A->B->A) or multiple cascade paths to one table. SQL Server disallows this to prevent ambiguous cascade ordering and infinite loops.

How to fix it

Define the foreign key as ON DELETE NO ACTION / ON UPDATE NO ACTION (remove the cascade): ALTER TABLE child ADD CONSTRAINT fk ... FOREIGN KEY (...) REFERENCES parent(...) ON DELETE NO ACTION; Implement the required cascading delete with an INSTEAD OF DELETE trigger: the trigger deletes the child rows first, then the parent row (e.g. DELETE c FROM child c JOIN deleted d ON c.parent_id = d.id; DELETE e FROM parent e JOIN deleted d ON e.id = d.id;). An AFTER DELETE trigger does not work; the FK check runs before the trigger, so the delete is rejected with error 547. Review circular dependencies in the data model.

Open in DBAtlas →

More from this engine