Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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]
like image 312
jao Avatar asked Jul 19 '11 09:07

jao


1 Answers

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

like image 163
gbn Avatar answered Nov 28 '22 12:11

gbn