Cannot insert duplicate key row in object with index ncix_id with non-unique index

Oleksii Filipov 20 Reputation points
2024-09-09T10:38:28.17+00:00

Hello!

Microsoft SQL Server 2019 (RTM-CU20) (KB5024276) on Linux (CentOS Linux 7 (Core)) <X64>

We have a table with 3 indexes:

  1. FIX_ActionSerial - nonclustered, unique located on PRIMARY - ActionSerial
  2. ncix_planID - nonclustered located on PRIMARY - PlanId
  3. PK_CampaignSummary - clustered, ignore duplicate keys, unique, primary key located on PRIMARY - MonthId, WeekId, ActionSerial, LifecycleStageId, KpiId

Index number 2 was created recently and immediately after that we started to get an error message:

Cannot write data to SQL 
Cannot insert duplicate key row in object 'mpe.CampaignSummary' 
with unique index 'ncix_planID'. 
The duplicate key value is (794, 94, 404, 39318, 0, 1).\n
The statement has been terminated

Those values from the error message are PlanId from nonclustered non-unique index + all columns from PK. It is completed on a rerun.

Does anybody has an idea:

  1. Why we have ncix_PlanID index in an error message saying it is UNIQUE? (yes I know we still have every index unique behind the scene)
  2. Why we see values like that - yes I know nonclustered index contains clustered key but it should be behind the scene, isn't it?

I would appreciate any thoughts.

P.S. We do not have indexed views on a table.

Thanks!

SQL Server Other
{count} votes

Your answer

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