SQL Server 2022 reports a unique index violation for a non-unique index

Zalán Kovalcsik 0 Reputation points
2026-08-25T06:30:09.3433333+00:00

Under SQL Server 2022, an intermittent 2601 error occurs during a scheduled data load.

SQL Server reports a duplicate key violation on a non-unique index, while referring to the index as a unique index.

Another anomaly is that the duplicate key reported in the error message contains one more value than the actual number of key columns in the affected index.

For example, the index has 3 key columns:

(transportation_flag, valid_from, valid_to)

but the error message reports 4 values:

(A, <date>, <date>, <identifier>)

Therefore, the duplicate key reported by SQL Server contains 4 values, while the index has only 3 key columns.

The error occurs intermittently and does not happen on every execution.

SQL Server version: Microsoft SQL Server 2022 (RTM-CU21)

Could this be a known SQL Server 2022 bug, and is there a fix or workaround available for this issue?

SQL Server Database Engine

1 answer

Sort by: Most helpful
  1. Deepesh Dhake 840 Reputation points
    2026-08-25T14:46:15.3333333+00:00

    SQL Server appends the clustering key to non-unique nonclustered indexes to make them internally unique. This is documented, well-established behavior.

    Since date_from is already a key column in both indexes, only the missing PK column id_1 is appended which is why one extra value appears, not two.

    Therefore 512479 and 512501 are id_1 values, and both collisions reduce to a duplicate (id_1, date_from) which is also your PK.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.