---
title: "Violation of PRIMARY KEY constraint"
description: "Violation of PRIMARY KEY constraint"
keywords: "Violation of PRIMARY KEY constraint NAV SQL error message"
url: "https://myrapidi.com/wiki/violation_of_primary_key_constraint"
locale: "en"
published: "2025-01-13T12:24:43Z"
modified: "2025-01-13T12:25:11Z"
---

**Scenario** : Occurs when trying to insert a record with a duplicate value in a column that has a PRIMARY KEY constraint.  
  
**Error Message** : `Native Error Code: 2627 SQL State: 23000 [Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object 'dbo.XYZ'. The duplicate key value is (XZZ).`  
  
**Cause** : The record already exists in the database, or the key field is not unique in the source data.

**Resolution** :  
  

- Check if the record already exists by using a query (`SELECT * FROM [Table] WHERE [PrimaryKeyColumn] = 'Value'`).
- Ensure the source data generates unique keys (e.g., combining fields or using GUIDs).
