When I'm trying to update a record I get error #1062 - Duplicate entry for key 'ID_UNIQUE'





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I'm using the following stored-procedure to update a table:



DELIMITER $$
CREATE DEFINER=`developer`@`localhost` PROCEDURE `update_patient`(IN `patient_id` INT(11), IN `name` VARCHAR(45), IN `surname` VARCHAR(45), IN `middle_name` VARCHAR(45), IN `email` VARCHAR(45), IN `phone` VARCHAR(45), IN `mobile` VARCHAR(45), IN `address_id` INT(11), IN `address_no` VARCHAR(8), IN `ID` VARCHAR(45), IN `DOB` DATE)
NO SQL
UPDATE
patient
SET name = name,
surname = surname,
middle_name = middle_name,
email = email,
phone = phone,
mobile = mobile,
address_id = address_id,
address_no = address_no,
ID = ID,
DOB = DOB
WHERE
patient_id = patient_id
LIMIT 1;
END$$
DELIMITER ;


When I'm trying to call it through phpmyadmin I get the error: #1062 - Duplicate entry '844844' for key 'ID_UNIQUE'



844844 refers to ID field. I have this field in patient table and I want to update the patient's data. However, the primary key of patient table is patiend_id and not ID.



Do you know how to fix the error?










share|improve this question





























    1















    I'm using the following stored-procedure to update a table:



    DELIMITER $$
    CREATE DEFINER=`developer`@`localhost` PROCEDURE `update_patient`(IN `patient_id` INT(11), IN `name` VARCHAR(45), IN `surname` VARCHAR(45), IN `middle_name` VARCHAR(45), IN `email` VARCHAR(45), IN `phone` VARCHAR(45), IN `mobile` VARCHAR(45), IN `address_id` INT(11), IN `address_no` VARCHAR(8), IN `ID` VARCHAR(45), IN `DOB` DATE)
    NO SQL
    UPDATE
    patient
    SET name = name,
    surname = surname,
    middle_name = middle_name,
    email = email,
    phone = phone,
    mobile = mobile,
    address_id = address_id,
    address_no = address_no,
    ID = ID,
    DOB = DOB
    WHERE
    patient_id = patient_id
    LIMIT 1;
    END$$
    DELIMITER ;


    When I'm trying to call it through phpmyadmin I get the error: #1062 - Duplicate entry '844844' for key 'ID_UNIQUE'



    844844 refers to ID field. I have this field in patient table and I want to update the patient's data. However, the primary key of patient table is patiend_id and not ID.



    Do you know how to fix the error?










    share|improve this question

























      1












      1








      1








      I'm using the following stored-procedure to update a table:



      DELIMITER $$
      CREATE DEFINER=`developer`@`localhost` PROCEDURE `update_patient`(IN `patient_id` INT(11), IN `name` VARCHAR(45), IN `surname` VARCHAR(45), IN `middle_name` VARCHAR(45), IN `email` VARCHAR(45), IN `phone` VARCHAR(45), IN `mobile` VARCHAR(45), IN `address_id` INT(11), IN `address_no` VARCHAR(8), IN `ID` VARCHAR(45), IN `DOB` DATE)
      NO SQL
      UPDATE
      patient
      SET name = name,
      surname = surname,
      middle_name = middle_name,
      email = email,
      phone = phone,
      mobile = mobile,
      address_id = address_id,
      address_no = address_no,
      ID = ID,
      DOB = DOB
      WHERE
      patient_id = patient_id
      LIMIT 1;
      END$$
      DELIMITER ;


      When I'm trying to call it through phpmyadmin I get the error: #1062 - Duplicate entry '844844' for key 'ID_UNIQUE'



      844844 refers to ID field. I have this field in patient table and I want to update the patient's data. However, the primary key of patient table is patiend_id and not ID.



      Do you know how to fix the error?










      share|improve this question














      I'm using the following stored-procedure to update a table:



      DELIMITER $$
      CREATE DEFINER=`developer`@`localhost` PROCEDURE `update_patient`(IN `patient_id` INT(11), IN `name` VARCHAR(45), IN `surname` VARCHAR(45), IN `middle_name` VARCHAR(45), IN `email` VARCHAR(45), IN `phone` VARCHAR(45), IN `mobile` VARCHAR(45), IN `address_id` INT(11), IN `address_no` VARCHAR(8), IN `ID` VARCHAR(45), IN `DOB` DATE)
      NO SQL
      UPDATE
      patient
      SET name = name,
      surname = surname,
      middle_name = middle_name,
      email = email,
      phone = phone,
      mobile = mobile,
      address_id = address_id,
      address_no = address_no,
      ID = ID,
      DOB = DOB
      WHERE
      patient_id = patient_id
      LIMIT 1;
      END$$
      DELIMITER ;


      When I'm trying to call it through phpmyadmin I get the error: #1062 - Duplicate entry '844844' for key 'ID_UNIQUE'



      844844 refers to ID field. I have this field in patient table and I want to update the patient's data. However, the primary key of patient table is patiend_id and not ID.



      Do you know how to fix the error?







      mysql stored-procedures phpmyadmin






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 14:02









      zinonzinon

      1,62543671




      1,62543671
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The problem is your input params for the Stored procedure are same as your column names in the table. This is leading to ambiguous behaviour.



          Eg: In SET name = name ; how does MySQL resolve which one of this is the param value and which one is the column name ?



          I generally prefix IN params with in_ and OUT with out_ for code readability and avoiding ambiguous behaviour.



          DELIMITER $$
          CREATE definer=`developer`@`localhost`
          PROCEDURE `update_patient`(IN `in_patient_id` INT(11),
          IN `in_name` VARCHAR(45),
          IN `in_surname` VARCHAR(45),
          IN `in_middle_name` VARCHAR(45),
          IN `in_email` VARCHAR(45),
          IN `in_phone` VARCHAR(45),
          IN `in_mobile` VARCHAR(45),
          IN `in_address_id` INT(11),
          IN `in_address_no` VARCHAR(8),
          IN `in_id` VARCHAR(45),
          IN `in_dob` date)
          NO SQL

          UPDATE patient
          SET name = in_name,
          surname = in_surname,
          middle_name = in_middle_name,
          email = in_email,
          phone = in_phone,
          mobile = in_mobile,
          address_id = in_address_id,
          address_no = in_address_no,
          id = in_id,
          dob = in_dob
          WHERE patient_id = in_patient_id
          LIMIT 1;

          END$$
          DELIMITER ;





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448120%2fwhen-im-trying-to-update-a-record-i-get-error-1062-duplicate-entry-for-key%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The problem is your input params for the Stored procedure are same as your column names in the table. This is leading to ambiguous behaviour.



            Eg: In SET name = name ; how does MySQL resolve which one of this is the param value and which one is the column name ?



            I generally prefix IN params with in_ and OUT with out_ for code readability and avoiding ambiguous behaviour.



            DELIMITER $$
            CREATE definer=`developer`@`localhost`
            PROCEDURE `update_patient`(IN `in_patient_id` INT(11),
            IN `in_name` VARCHAR(45),
            IN `in_surname` VARCHAR(45),
            IN `in_middle_name` VARCHAR(45),
            IN `in_email` VARCHAR(45),
            IN `in_phone` VARCHAR(45),
            IN `in_mobile` VARCHAR(45),
            IN `in_address_id` INT(11),
            IN `in_address_no` VARCHAR(8),
            IN `in_id` VARCHAR(45),
            IN `in_dob` date)
            NO SQL

            UPDATE patient
            SET name = in_name,
            surname = in_surname,
            middle_name = in_middle_name,
            email = in_email,
            phone = in_phone,
            mobile = in_mobile,
            address_id = in_address_id,
            address_no = in_address_no,
            id = in_id,
            dob = in_dob
            WHERE patient_id = in_patient_id
            LIMIT 1;

            END$$
            DELIMITER ;





            share|improve this answer




























              1














              The problem is your input params for the Stored procedure are same as your column names in the table. This is leading to ambiguous behaviour.



              Eg: In SET name = name ; how does MySQL resolve which one of this is the param value and which one is the column name ?



              I generally prefix IN params with in_ and OUT with out_ for code readability and avoiding ambiguous behaviour.



              DELIMITER $$
              CREATE definer=`developer`@`localhost`
              PROCEDURE `update_patient`(IN `in_patient_id` INT(11),
              IN `in_name` VARCHAR(45),
              IN `in_surname` VARCHAR(45),
              IN `in_middle_name` VARCHAR(45),
              IN `in_email` VARCHAR(45),
              IN `in_phone` VARCHAR(45),
              IN `in_mobile` VARCHAR(45),
              IN `in_address_id` INT(11),
              IN `in_address_no` VARCHAR(8),
              IN `in_id` VARCHAR(45),
              IN `in_dob` date)
              NO SQL

              UPDATE patient
              SET name = in_name,
              surname = in_surname,
              middle_name = in_middle_name,
              email = in_email,
              phone = in_phone,
              mobile = in_mobile,
              address_id = in_address_id,
              address_no = in_address_no,
              id = in_id,
              dob = in_dob
              WHERE patient_id = in_patient_id
              LIMIT 1;

              END$$
              DELIMITER ;





              share|improve this answer


























                1












                1








                1







                The problem is your input params for the Stored procedure are same as your column names in the table. This is leading to ambiguous behaviour.



                Eg: In SET name = name ; how does MySQL resolve which one of this is the param value and which one is the column name ?



                I generally prefix IN params with in_ and OUT with out_ for code readability and avoiding ambiguous behaviour.



                DELIMITER $$
                CREATE definer=`developer`@`localhost`
                PROCEDURE `update_patient`(IN `in_patient_id` INT(11),
                IN `in_name` VARCHAR(45),
                IN `in_surname` VARCHAR(45),
                IN `in_middle_name` VARCHAR(45),
                IN `in_email` VARCHAR(45),
                IN `in_phone` VARCHAR(45),
                IN `in_mobile` VARCHAR(45),
                IN `in_address_id` INT(11),
                IN `in_address_no` VARCHAR(8),
                IN `in_id` VARCHAR(45),
                IN `in_dob` date)
                NO SQL

                UPDATE patient
                SET name = in_name,
                surname = in_surname,
                middle_name = in_middle_name,
                email = in_email,
                phone = in_phone,
                mobile = in_mobile,
                address_id = in_address_id,
                address_no = in_address_no,
                id = in_id,
                dob = in_dob
                WHERE patient_id = in_patient_id
                LIMIT 1;

                END$$
                DELIMITER ;





                share|improve this answer













                The problem is your input params for the Stored procedure are same as your column names in the table. This is leading to ambiguous behaviour.



                Eg: In SET name = name ; how does MySQL resolve which one of this is the param value and which one is the column name ?



                I generally prefix IN params with in_ and OUT with out_ for code readability and avoiding ambiguous behaviour.



                DELIMITER $$
                CREATE definer=`developer`@`localhost`
                PROCEDURE `update_patient`(IN `in_patient_id` INT(11),
                IN `in_name` VARCHAR(45),
                IN `in_surname` VARCHAR(45),
                IN `in_middle_name` VARCHAR(45),
                IN `in_email` VARCHAR(45),
                IN `in_phone` VARCHAR(45),
                IN `in_mobile` VARCHAR(45),
                IN `in_address_id` INT(11),
                IN `in_address_no` VARCHAR(8),
                IN `in_id` VARCHAR(45),
                IN `in_dob` date)
                NO SQL

                UPDATE patient
                SET name = in_name,
                surname = in_surname,
                middle_name = in_middle_name,
                email = in_email,
                phone = in_phone,
                mobile = in_mobile,
                address_id = in_address_id,
                address_no = in_address_no,
                id = in_id,
                dob = in_dob
                WHERE patient_id = in_patient_id
                LIMIT 1;

                END$$
                DELIMITER ;






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 14:05









                Madhur BhaiyaMadhur Bhaiya

                19.6k62336




                19.6k62336
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448120%2fwhen-im-trying-to-update-a-record-i-get-error-1062-duplicate-entry-for-key%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Academy of Television Arts & Sciences

                    L'Équipe

                    1995 France bombings