开发者

while updating a row: Cannot insert duplicate key row in object 'dbo.tblRelatie' with unique index 'idxRelatiesoortRelatiecode'

开发者 https://www.devze.com 2023-03-21 01:57 出处:网络
when UPDATEing a row I get the above error. idxRelatiesoortRelatiecode consists of fldRelatieSoort and fldRelatieSoort and the combination of both exists only once in the table.

when UPDATEing a row I get the above error. idxRelatiesoortRelatiecode consists of fldRelatieSoort and fldRelatieSoort and the combination of both exists only once in the table.

So what could be the reason for this error?

Update Here is the update script

UPDATE [SQL].[MyDatabase].dbo.tblRelatie SET 
fldNaam = 'De heer A. Removed', 
fldAdres = 'Removed 12', 
fldPostcode = '1234 AA', fldPlaats = 'Removed', 
fldCorrespondentieAdres = 'Removed 12', 
fldCorrespondentieAdresPostcode = '1234 AA', 
fldCorrespondentieAdresPlaats = 'Removed', 
fldRelatieSoort = 1,
fldRelatiecode = 907534, 
fldCorrespondentieAdresLandID = 1, fldMobieleTelefoon = '', fldTe开发者_运维技巧lefoon = '', fldFax = '',  fldEmail = '', fldWebsiteUrl = '', fldBankrekeningnummer = '', fldNaamRekeninghouder = '', 
fldPlaatsRekeninghouder = '', fldKrediettermijn = 30, fldLandID = 1 
WHERE fldRelatieID =1507;

and this is the idxRelatiesoortRelatiecode:

CREATE UNIQUE NONCLUSTERED INDEX [idxRelatiesoortRelatiecode] 
ON [dbo].[tblRelatie] 
(
    [fldRelatieSoort] ASC,
    [fldRelatiecode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF,
IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON,    
ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]


There isn't much ambiguity in the error message: you are setting a duplicate somewhere

  • Either: the combination already exists and you are trying to insert it again
  • Or: it doesn't exist and you are updating multiple rows with the same combination

Or the overlap:

  • the combination already exists and you are updating multiple rows with the same combination

Unless the index or such is wrong...


In my case case there's a constraint on the table, the constraint is like this

ALTER TABLE {my_table}
   ADD CONSTRAINT {CONSTRAINT_ID} UNIQUE (my_table.colA, my_table.colB) 

I am trying to update a data that is already existing (colA and colB), so I just have to check if the data im trying to update is present.

0

精彩评论

暂无评论...
验证码 换一张
取 消