DBAtlas · Database operations atlas

547: The INSERT/UPDATE/DELETE statement conflicted with the FOREIGN KEY / CHECK constraint

SQL Server

What does it mean?

The statement violated a FOREIGN KEY or CHECK constraint. Either it referenced a parent row that does not exist, wrote a value that breaks a CHECK rule, or tried to delete a parent row that is still referenced.

Why does it happen?

FK: the parent row referenced by the inserted child row does not exist. DELETE/UPDATE: child rows depend on the parent row being deleted/changed. CHECK: the column value does not satisfy the defined condition.

How to fix it

Insert the parent row first, then the child row. For deletes, remove the dependent rows first or define ON DELETE CASCADE where appropriate. For a CHECK violation, make the value comply with the rule. Identify the violated constraint from the constraint name in the error text.

Open in DBAtlas →

More from this engine