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

烂漫一生 提交于 2020-07-05 10:12:29

问题


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 = '', fldTelefoon = '', 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]

回答1:


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...



来源:https://stackoverflow.com/questions/6744683/while-updating-a-row-cannot-insert-duplicate-key-row-in-object-dbo-tblrelatie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!