SQL Server Error 2627 — Violation of PRIMARY KEY constraint

Violation of PRIMARY KEY constraint 'PK_X'. Cannot insert duplicate key in object 'dbo.X'. The duplicate key value is (...).

You tried to insert or update a row with a primary key value that already exists in the table.

Common causes

How to fix it

  1. The error message itself tells you the duplicate key value — start there.
  2. Check for concurrent processes generating IDs outside of an IDENTITY column or sequence.
  3. For ETL/imports, add an existence check (MERGE or WHERE NOT EXISTS) before inserting.
  4. If it's an identity column drift issue, reseed it: DBCC CHECKIDENT ('table', RESEED, correct_value).

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

Try error explainer free →

Related