Unable to insert into table after creating an After insert trigger
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
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.
add a comment |
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
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.
add a comment |
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
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
mysql trigger
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.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Instead of saying marketplace_saleperpartner.
, say NEW.
(or OLD.
, if appropriate).
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Instead of saying marketplace_saleperpartner.
, say NEW.
(or OLD.
, if appropriate).
add a comment |
Instead of saying marketplace_saleperpartner.
, say NEW.
(or OLD.
, if appropriate).
add a comment |
Instead of saying marketplace_saleperpartner.
, say NEW.
(or OLD.
, if appropriate).
Instead of saying marketplace_saleperpartner.
, say NEW.
(or OLD.
, if appropriate).
answered Dec 12 '15 at 20:18
Rick JamesRick James
41.5k22258
41.5k22258
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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