MYSQL ERROR - need desperate help

  • Hi,

    Im having a problem with new players selecting a player class. Keep getting this error.

    Message:

    Error Executing Database Query.

    URL:

    /ClassSelect.cfm?

    Location:

    C:\websites\myConvicts\www\ClassSelect.cfm

    Line #:

    36

    SQL:

    INSERT INTO DR_Player_Upgrade (PlayerID, UpgradeID, PurchaseDate) VALUES (2930848,27,CURRENT_TIMESTAMP)

    [Macromedia][SQLServer JDBC Driver][SQLServer]Violation of PRIMARY KEY constraint 'PK_DR_Player_Upgrade'. Cannot insert duplicate key in object 'dbo.DR_Player_Upgrade'. The duplicate key value is (2930848, 27).

    Please help, very desperate.

    Thanks,

    Anthony.

    • This topic was modified 3 years, 11 months ago by  Anth.
  • The error is telling you that value already exists at the time of execution. You can confirm by executing

    SELECT * FROM DR_Player_Upgrade WHERE PlayerID = 2930848 AND UpgradeID = 27

    If so, you will need to debug your code to determine why it was inserted before you thought and/or why it is trying to insert again when it already exists. Was the player really already upgraded?

    NOTE: This is a SQL Server 2019 Administration group.

  • The error tells you exactly what the issue is.  You are trying to insert a record that already exists in the table.

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Hi ratbak

    Thanks for reply.

    Yes I can see it says duplicate but I cant work out what's been changed and how to fix this.

    Not sure how to solve it.

  • Something, someone has already put that piece of information into the table, so you need to look at the logic and go back and see why you are trying to insert it again?  If a processing failure further down the chain failed then you need to look at transactions and bundling code together so it all completes as one unit rather than multiple units of work that way you can re-run a segment of work without having to work out why your getting duplication errors.

     

     

  • You could add code to check for a record's existence, and only INSERT if it is not already there.

    That will prevent the error, but does not answer the question of why it's trying to enter a duplicate.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply