Sample Header Ad - 728x90

Trigger to UPDATE after UPDATE?

14 votes
3 answers
45962 views
I want to make a trigger to record the time of any update as: CREATE TRIGGER col_update AFTER UPDATE ON col FOR EACH ROW BEGIN UPDATE col SET updated=NOW() WHERE id=NEW.id; // or OLD.id END The problem is that when this trigger tries to update the updated column, it is also another update event, which runs the trigger. This will create an infinite loop, which does not work. How can I store the update time in the corresponding column? I wish to use a trigger because there are many columns in the table. If I try to set the update time manually, I would need to modify many queries.
Asked by Googlebot (4551 rep)
Jul 3, 2012, 04:48 PM
Last activity: Aug 19, 2021, 07:48 PM