MySQL Forums
Forum List  »  Newbie

Can't update table XXX in stored function/trigger because it is already used
Posted by: Michael Gardner
Date: August 06, 2014 05:24PM

Hello,

I have a table, "customers", that holds customer information. The table has a column named, "RowVersion", which is an Int64 and is used for concurrency checking. What I want to do is update RowVersion after an insert or update operation. When I implemented the following triggers, I receive this error:

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

So, it appears that I am doing somthing wrong with respect to triggers and my goals. I am sure that a lot of people are implementing row counters for concurrency, but I could not find anything in my searching. I'd appreciate your help in figuring out this issue.

CREATE TRIGGER 'CustomersInsertIncrementRowVersion' AFTER INSERT ON 'customers'
FOR EACH ROW
BEGIN
UPDATE customers set RowVersion = RowVersion + 1 where CustomerId = NEW.CustomerId
END

CREATE TRIGGER 'CustomersUpdateIncrementRowVersion' AFTER UPDATE ON 'customers'
FOR EACH ROW
BEGIN
UPDATE customers set RowVersion = RowVersion + 1 where CustomerId = OLD.CustomerId
END

Thanks,
Mike

Options: ReplyQuote


Subject
Written By
Posted
Can't update table XXX in stored function/trigger because it is already used
August 06, 2014 05:24PM


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.