547: The INSERT/UPDATE/DELETE statement conflicted with the FOREIGN KEY / CHECK constraint
SQL ServerWhat 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.
More from this engine
- 1205Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim
- 2627Violation of PRIMARY KEY / UNIQUE KEY constraint. Cannot insert duplicate key in object
- 2601Cannot insert duplicate key row in object with unique index. The duplicate key value is ...
- 18456Login failed for user
- 8152String or binary data would be truncated
- 2628String or binary data would be truncated in table, column ...; truncated value
- 1222Lock request time out period exceeded