SQL Server Error 547 — The statement conflicted with the FOREIGN KEY constraint

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_X". The conflict occurred in database "Y", table "dbo.Z", column 'W'.

You tried to insert/update a row referencing a parent value that doesn't exist, or delete a parent row that child rows still depend on. The same error number also covers CHECK constraint violations, so read the message carefully — it names which constraint fired.

Common causes

How to fix it

  1. Read the message for the exact constraint and column named — it tells you which relationship failed.
  2. For inserts: confirm the parent row exists first, or fix insert ordering in the application/transaction.
  3. For deletes: either cascade the delete (ON DELETE CASCADE, used carefully) or explicitly remove/reassign child rows first.
  4. For CHECK constraint hits: validate the incoming value against the constraint definition (sys.check_constraints) before writing.

Paste your full error and the statement here for a fix specific to your schema.

Try error explainer free →

Related