Db2 SQL0803N: One or more values in the INSERT or UPDATE statement violate a unique index (SQLSTATE 23505)
The statement would create a duplicate value in a column or index that must be unique.
SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique indexSQLCODE=-803, SQLSTATE=23505DB2 duplicate key SQL0803NSQLSTATE=23505 Db2 Meaning
Find the existing row with the same key, use MERGE or check-then-update logic, fix sequence/identity values, and read which index the message names (SQLERRMC contains the constraint/index ID; look it up in syscat.indexes).
Common causes
- Duplicate primary/unique key value
- Identity/sequence out of sync after a load
- Concurrent inserts of the same key
- Retry inserting an already committed row
- Case/whitespace-normalised duplicates
⚡ Quick fix
- Use
MERGE INTOfor upserts - Identify the index in
syscat.indexes - Reset the identity/sequence value
Detailed fix by platform
SQL
SELECT indschema, indname, colnames FROM syscat.indexes WHERE indname = 'SQL260101123456';
How to diagnose
- Key — Already exists?
- Sequence — In sync?
- Upsert — Needed?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 2627 SQL Server: Violation of PRIMARY KEY constraint 'x'. Cannot insert duplicate key in object 'y'. (Msg 2627)
- aggregate in WHERE ERROR: aggregate functions are not allowed in WHERE (use HAVING) / MySQL 1111 Invalid use of group function
- cartesian Query returns far too many rows: accidental Cartesian product (missing JOIN condition)
Most viewed in SQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 18 Nov 2026