Unable to insert into table after creating an After insert trigger












0















I have two tables

Table one: default_sellers_commissions have:



id
value - INT


Table two: marketplace_saleperpartner have:



id
userID
commission - INT default '0.00'
commission_id


what I need is after insert a new row in table marketplace_saleperpartner update the marketplace_saleperpartner.commission value with value from default_sellers_commissions.value where the marketplace_saleperpartner.commission_id = default_sellers_commissions.id



So I create a trigger :



CREATE TRIGGER `marketplacedefaultcommission`
AFTER INSERT ON `marketplace_saleperpartner`
FOR EACH ROW
UPDATE marketplace_saleperpartner
SET `marketplace_saleperpartner`.`commision` = `default_sellers_commissions`.`value`
WHERE `marketplace_saleperpartner`.`comm_id` = `default_sellers_commissions`.`id`
AND `marketplace_saleperpartner`.`commision`='0.00';


P.S:

for some reason I need the marketplace_saleperpartner.commision to insert for the first time with value='0.00'



now I am getting this error while trying to insert a new row into table marketplace_saleperpartner



MySql Error: Can't update table in stored function/trigger because it is already used by statement which invoked this stored function/trigger


Any help please ?










share|improve this question














bumped to the homepage by Community 7 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0















    I have two tables

    Table one: default_sellers_commissions have:



    id
    value - INT


    Table two: marketplace_saleperpartner have:



    id
    userID
    commission - INT default '0.00'
    commission_id


    what I need is after insert a new row in table marketplace_saleperpartner update the marketplace_saleperpartner.commission value with value from default_sellers_commissions.value where the marketplace_saleperpartner.commission_id = default_sellers_commissions.id



    So I create a trigger :



    CREATE TRIGGER `marketplacedefaultcommission`
    AFTER INSERT ON `marketplace_saleperpartner`
    FOR EACH ROW
    UPDATE marketplace_saleperpartner
    SET `marketplace_saleperpartner`.`commision` = `default_sellers_commissions`.`value`
    WHERE `marketplace_saleperpartner`.`comm_id` = `default_sellers_commissions`.`id`
    AND `marketplace_saleperpartner`.`commision`='0.00';


    P.S:

    for some reason I need the marketplace_saleperpartner.commision to insert for the first time with value='0.00'



    now I am getting this error while trying to insert a new row into table marketplace_saleperpartner



    MySql Error: Can't update table in stored function/trigger because it is already used by statement which invoked this stored function/trigger


    Any help please ?










    share|improve this question














    bumped to the homepage by Community 7 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      I have two tables

      Table one: default_sellers_commissions have:



      id
      value - INT


      Table two: marketplace_saleperpartner have:



      id
      userID
      commission - INT default '0.00'
      commission_id


      what I need is after insert a new row in table marketplace_saleperpartner update the marketplace_saleperpartner.commission value with value from default_sellers_commissions.value where the marketplace_saleperpartner.commission_id = default_sellers_commissions.id



      So I create a trigger :



      CREATE TRIGGER `marketplacedefaultcommission`
      AFTER INSERT ON `marketplace_saleperpartner`
      FOR EACH ROW
      UPDATE marketplace_saleperpartner
      SET `marketplace_saleperpartner`.`commision` = `default_sellers_commissions`.`value`
      WHERE `marketplace_saleperpartner`.`comm_id` = `default_sellers_commissions`.`id`
      AND `marketplace_saleperpartner`.`commision`='0.00';


      P.S:

      for some reason I need the marketplace_saleperpartner.commision to insert for the first time with value='0.00'



      now I am getting this error while trying to insert a new row into table marketplace_saleperpartner



      MySql Error: Can't update table in stored function/trigger because it is already used by statement which invoked this stored function/trigger


      Any help please ?










      share|improve this question














      I have two tables

      Table one: default_sellers_commissions have:



      id
      value - INT


      Table two: marketplace_saleperpartner have:



      id
      userID
      commission - INT default '0.00'
      commission_id


      what I need is after insert a new row in table marketplace_saleperpartner update the marketplace_saleperpartner.commission value with value from default_sellers_commissions.value where the marketplace_saleperpartner.commission_id = default_sellers_commissions.id



      So I create a trigger :



      CREATE TRIGGER `marketplacedefaultcommission`
      AFTER INSERT ON `marketplace_saleperpartner`
      FOR EACH ROW
      UPDATE marketplace_saleperpartner
      SET `marketplace_saleperpartner`.`commision` = `default_sellers_commissions`.`value`
      WHERE `marketplace_saleperpartner`.`comm_id` = `default_sellers_commissions`.`id`
      AND `marketplace_saleperpartner`.`commision`='0.00';


      P.S:

      for some reason I need the marketplace_saleperpartner.commision to insert for the first time with value='0.00'



      now I am getting this error while trying to insert a new row into table marketplace_saleperpartner



      MySql Error: Can't update table in stored function/trigger because it is already used by statement which invoked this stored function/trigger


      Any help please ?







      mysql trigger






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 1 '15 at 14:44









      Ashraf HefnyAshraf Hefny

      13115




      13115





      bumped to the homepage by Community 7 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 7 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Instead of saying marketplace_saleperpartner., say NEW. (or OLD., if appropriate).






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "182"
            };
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2fdba.stackexchange.com%2fquestions%2f122573%2funable-to-insert-into-table-after-creating-an-after-insert-trigger%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









            0














            Instead of saying marketplace_saleperpartner., say NEW. (or OLD., if appropriate).






            share|improve this answer




























              0














              Instead of saying marketplace_saleperpartner., say NEW. (or OLD., if appropriate).






              share|improve this answer


























                0












                0








                0







                Instead of saying marketplace_saleperpartner., say NEW. (or OLD., if appropriate).






                share|improve this answer













                Instead of saying marketplace_saleperpartner., say NEW. (or OLD., if appropriate).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 12 '15 at 20:18









                Rick JamesRick James

                41.5k22258




                41.5k22258






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Database Administrators Stack Exchange!


                    • 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%2fdba.stackexchange.com%2fquestions%2f122573%2funable-to-insert-into-table-after-creating-an-after-insert-trigger%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







                    Popular posts from this blog

                    SQL Server 17 - Attemping to backup to remote NAS but Access is denied

                    Always On Availability groups resolving state after failover - Remote harden of transaction...

                    Restoring from pg_dump with foreign key constraints