mysql触发器

mysql的触发器不能对本表进行update操作,如下面 的示例,直接报
Can’t update table ‘tbl’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger 错误,


如果你在触发器里面对刚刚插入的数据进行了 insert/update, 则出现这个问题。因为会造成循环的调用.

create trigger test
before update on test
for each row
  update test set NEW.updateTime = NOW() where id=NEW.ID;
END


应该使用set操作,而不是在触发器里使用 update,比如

create trigger test
before update on test
for each row
set NEW.updateTime = NOW();
END

你可能感兴趣的:(mysql)