2627 SQL Origin: Data OSI layer 7 · Application Last updated 14 Oct 2026

SQL Server: Violation of PRIMARY KEY constraint 'x'. Cannot insert duplicate key in object 'y'. (Msg 2627)

An insert duplicated a primary key or unique constraint value.

Exact message you may see Violation of PRIMARY KEY constraintViolation of UNIQUE KEY constraintCannot insert duplicate key in object
Seen on: SQL

Meaning

2627 is for constraints; 2601 is the same thing for unique indexes. The message includes the duplicate key value.

Common causes

  • Duplicate key value
  • Re-inserting seed data
  • Identity reseeded below existing values

⚡ Quick fix

  1. Use MERGE or check existence before insert
  2. Handle the error as "already exists"
  3. Reseed identity correctly (DBCC CHECKIDENT)

Detailed fix by platform

SQL

  1. DBCC CHECKIDENT ('dbo.Orders', RESEED);

How to diagnose

  1. Key — Duplicate value shown?
  2. Identity — Reseeded?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

102 — SQL Server: Incorrect syntax near 'x'. (Msg 102) (SQL)1021062 — MySQL ERROR 1062 (23000): Duplicate entry for key (MySQL)1062245 — SQL Server: Conversion failed when converting the varchar value 'x' to data type int. (Msg 245) (SQL)245515 — SQL Server Msg 515: Cannot insert the value NULL into column 'X', table 'Y'; column does not allow nulls (SQL)515544 — SQL Server: Cannot insert explicit value for identity column in table 'x' when IDENTITY_INSERT is set to OFF. (SQL)5448115 — SQL Server: Arithmetic overflow error converting expression to data type int. (Msg 8115) (SQL)8115ALREADY_EXISTS — API Error: Resource already exists (ALREADY_EXISTS / resource_already_exists / 409) (API)ALREADY_EXISTSAutopilot — GKE Autopilot rejected the workload: resources adjusted / violates Autopilot constraints (Google Cloud / Firebase)Autopilot2627

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.