MySQL triggers cannot update rows in same table the trigger is assigned to. Suggested workaround?

You can actually up the rows in the same table as the trigger. The thread you linked to even has the solution.

For example:

TestTable ( id / lastmodified / random )

create trigger insert_lastmod
before insert on TestTable
for each row
set NEW.lastmodified = NOW();

insert into TestTable ( `random` ) values ( 'Random' );

select * from TestTable;
+----+---------------------+---------------------+
| id | lastmodified        | random              |
+----+---------------------+---------------------+
|  1 | 2010-12-22 14:15:23 | Random              |
+----+---------------------+---------------------+

Leave a Comment