SQL Server "Cannot insert duplicate key row" — Error 2601 or 2627?
Differences between SQL Server Error 2601 (unique index) and 2627 (unique constraint/PK), race conditions in IF NOT EXISTS, idempotent TRY/CATCH, MERGE WITH (HOLDLOCK), and IGNORE_DUP_KEY pitfalls.
Operational Verification & Reliability Metadata
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
Violation of UNIQUE KEY constraint 'UQ_Kullanici_Email'.
Cannot insert duplicate key in object 'dbo.Kullanici'. The duplicate key value is (a@b.com).- •Error 2627: Primary Key or Unique Constraint violation.
- •Error 2601: Unique Index violation.
▸Correct Resolution: Idempotent Exception Handling
BEGIN TRY
INSERT INTO dbo.Kullanici (Email, Ad) VALUES (@e, @ad);
END TRY
BEGIN CATCH
IF ERROR_NUMBER() IN (2601, 2627)
SELECT * FROM dbo.Kullanici WHERE Email = @e;
ELSE
THROW;
END CATCH- •Companion Guide (PostgreSQL): PostgreSQL duplicate key sequence desync
- •Engine Hub: SQL Server Production Hub
Other Database Error Triage Playbooks
Other battle-tested diagnostic guides for high-severity database errors.
SQL Server Error 18456: Root Cause by State Code Matrix
In Error 18456, the State code reveals the actual root cause. Specific fixes for State 5, 8, 11, 18, 38, and 40, with ERRORLOG extraction scripts.
SQL Server Error 1205 Deadlock: Graph Extraction and Prevention
Extracting the deadlock graph from the system_health Extended Events ring buffer, understanding victim election, and architectural resolution.
SQL Server Pool Timeout: Connection Pool Exhaustion Fix
Difference between connection pool timeout and query command timeout, detecting connection leaks, and .NET DbContext architectural fixes.