MySQL Forums
Forum List  »  Triggers

Update rows of same table with trigger
Posted by: Ulrich Riedel
Date: March 15, 2011 09:35AM

I have the need to update rows of a table by a trigger which is activated by another row of the same table.
This does not work and error 1442 will occure:
ERROR 1442: Can't update table 'x' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

My trigger should update all rows with the same id but different versionid in the same table. So my trigger below has two problems:
1. it's not allow to manipulate rows of the same table (my primary problem)
2. how may i select (and update) other rows

Is there any workaround, any idea to solve this problem?

My (not working) trigger looks like this:
TRIGGER x_au
AFTER UPDATE
ON x
FOR EACH ROW
BEGIN
IF 0 = new.VersionID THEN
UPDATE
x
SET
myrow = new.myrow
WHERE
xID = new.xID
AND
VersionID <> new.VersionID;
END IF;
END

Options: ReplyQuote


Subject
Views
Written By
Posted
Update rows of same table with trigger
6660
March 15, 2011 09:35AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.