dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Home/Error Library/sqlserver-547-foreign-key-constraint
SQL Server
SQL Server 2025 / 2022Data Integrity & Constraints
6 min read
The INSERT statement conflicted with the FOREIGN KEY constraint

SQL Server Error 547 — Why Foreign Key Rejects, and Which Row Is at Fault?

Diagnosing SQL Server Error 547 Foreign Key violations, finding orphan rows, why WITH CHECK is mandatory after NOCHECK to prevent is_not_trusted=1, and bulk loading sequencing.

Reviewed by:Principal Database Architect
Tested Versions: SQL Server 2025 (17.0 CU10 KB5125471) & 2022 (16.0 CU14)

Operational Verification & Reliability Metadata

Last Technical Review: 29 Ekim 2026
Tested VersionsSQL Server 2025 (17.0 CU10 KB5125471) & 2022 (16.0 CU14)
Required PrivilegesALTER TABLE and VIEW DEFINITION on sys.foreign_keys
Risk Assessment
MediumEnabling constraints with WITH NOCHECK leaves is_not_trusted=1, disabling query optimizer foreign key elimination
Expected OutputFully trusted Foreign Key constraint (is_not_trusted = 0) with zero orphan tuples
Rollback Procedure:Revert temporary constraints and restore original relational integrity
Microsoft Learn: SQL Server Foreign Key Constraints
First 60 Seconds Emergency Protocol:

The error string is a symptom, not the root cause. Do not restart the server blindly. Run the diagnostic queries below to pinpoint the actual failure mode.

▸Symptoms

plaintext
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Siparis_Musteri". The conflict occurred in database "app", table "dbo.Musteri", column 'Id'.

▸Diagnosis & Resolution

  1. 1Inspect Constraint Trust State:
sql
SELECT name, is_disabled, is_not_trusted FROM sys.foreign_keys WHERE name = 'FK_Siparis_Musteri';

If is_not_trusted = 1, SQL Server optimizer cannot use this constraint for join elimination.

  1. 1Locate Orphan Rows:
sql
SELECT c.* FROM dbo.Siparis c LEFT JOIN dbo.Musteri p ON p.Id = c.MusteriId WHERE c.MusteriId IS NOT NULL AND p.Id IS NULL;
  1. 1Re-enable with WITH CHECK:
sql
ALTER TABLE dbo.Siparis WITH CHECK CHECK CONSTRAINT FK_Siparis_Musteri;

Other Database Error Triage Playbooks

Other battle-tested diagnostic guides for high-severity database errors.

All Errors (50)