SQL Error - Insert happening on update
-
I have a stored procedure that is updating, but causing an insert error. Never seen that before.
Update MyCoolTable
Set MyValue=@passedInValue, SecondaryIdentifier=@secondID
WHERE PrimaryID = @primaryIDThere is an index on (SecondaryID,PrimaryID) that is being violated and I'm not sure why. :
Quote:
Cannot insert duplicate key in object 'dbo.MyCoolTable'. The duplicate key value is (secondaryIDValue, primaryIDValue).
Why is it trying to insert on an update? --edit-- Nevermind, I figured out what was happening (though not from the error message). It can't update the secondaryID because there can be more than one, which is what is causing the problem. I guess when they wrote it that could never ever happen.
If it moves, compile it
-
I have a stored procedure that is updating, but causing an insert error. Never seen that before.
Update MyCoolTable
Set MyValue=@passedInValue, SecondaryIdentifier=@secondID
WHERE PrimaryID = @primaryIDThere is an index on (SecondaryID,PrimaryID) that is being violated and I'm not sure why. :
Quote:
Cannot insert duplicate key in object 'dbo.MyCoolTable'. The duplicate key value is (secondaryIDValue, primaryIDValue).
Why is it trying to insert on an update? --edit-- Nevermind, I figured out what was happening (though not from the error message). It can't update the secondaryID because there can be more than one, which is what is causing the problem. I guess when they wrote it that could never ever happen.
If it moves, compile it
loctrice wrote:
I guess when they wrote it that could never ever happen
You might wanna post this a tip/trick. Maybe in this way it'll get searchable more easily by others having the same problem (and hopefully avoid another This is failing dunno why plz provide codez Q&A question)
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
-
loctrice wrote:
I guess when they wrote it that could never ever happen
You might wanna post this a tip/trick. Maybe in this way it'll get searchable more easily by others having the same problem (and hopefully avoid another This is failing dunno why plz provide codez Q&A question)
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
Andrei Straut wrote:
avoid another This is failing dunno why plz provide codez
was there something wrong with my question? I know it was a dumb question but my brain was just slow today. I guess I should/could have waited longer to post.
If it moves, compile it
-
Andrei Straut wrote:
avoid another This is failing dunno why plz provide codez
was there something wrong with my question? I know it was a dumb question but my brain was just slow today. I guess I should/could have waited longer to post.
If it moves, compile it
Oh, sorry for not making it clearer. I wasn't referring to your question (and I did upvote it), that was posted just fine from my point of view. I was referring to someone else having this problem in the future and posting in the manner I described. Didn't think you'd think I'd think that of your question (pun intended).
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
-
Oh, sorry for not making it clearer. I wasn't referring to your question (and I did upvote it), that was posted just fine from my point of view. I was referring to someone else having this problem in the future and posting in the manner I described. Didn't think you'd think I'd think that of your question (pun intended).
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.