Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Error - Insert happening on update

SQL Error - Insert happening on update

Scheduled Pinned Locked Moved Database
databasehelpquestionannouncement
5 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    loctrice
    wrote on last edited by
    #1

    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 = @primaryID

    There 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

    A 1 Reply Last reply
    0
    • L loctrice

      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 = @primaryID

      There 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

      A Offline
      A Offline
      Andrei Straut
      wrote on last edited by
      #2

      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.

      L 1 Reply Last reply
      0
      • A Andrei Straut

        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.

        L Offline
        L Offline
        loctrice
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • L loctrice

          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

          A Offline
          A Offline
          Andrei Straut
          wrote on last edited by
          #4

          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.

          L 1 Reply Last reply
          0
          • A Andrei Straut

            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.

            L Offline
            L Offline
            loctrice
            wrote on last edited by
            #5

            Andrei Straut wrote:

            Oh, sorry for not making it clearer.

            my fault. glad we got it cleared up :D

            If it moves, compile it

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups