MSSQLMSSQL 547
MSSQL 547: Foreign Key Constraint Conflict
SQL Server error 547 is raised when an INSERT, UPDATE, or DELETE violates a foreign key constraint. The error message names the conflicting constraint and table.
Example Query
DELETE FROM customers WHERE customer_id = 1; -- Fails if orders table has rows referencing customer_id 1
Common Causes
- 1Deleting a parent row that has dependent child rows
- 2Inserting a child row with a foreign key value not present in the parent
- 3Updating a primary key value that is referenced by child rows
How to Fix It
Delete or reassign child rows before deleting the parent. Add ON DELETE CASCADE to the constraint definition if automatic cleanup is desired. Use sp_fkeys 'table_name' to discover all foreign key relationships.
Need a reliable database?
Try Supabase — free PostgreSQL with a generous free tier. No credit card required.
Got a query causing this error?
Paste it into SQLbuddy and get an instant plain-English explanation with optimization tips.
Analyze My Query →