mySQL 1442 错误

信息如下 ERROR 1442 (HY000): Can't update table 'event1' in stored function/trigger becau

se it is already used by statement which invoked this stored function/trigger.

刚开始触发器定义如下

create trigger event_trigger BEFORE INSERT ON event1
FOR EACH ROW  UPDATE event1
SET  NEW.event_time =CURRENT_TIMESTAMP();

一般在定义触发器时 如果对本表做更新 应写成如下


drop trigger  if exists event_trigger ;
DELIMITER |
create trigger event_trigger BEFORE INSERT ON event1
FOR EACH ROW
SET  NEW.event_time =CURRENT_TIMESTAMP();
|
DELIMITER ;

不用写成全局的update 表名

可以参考国外的一篇文章

http://crazytoon.com/2008/03/03/mysql-error-1442-hy000-cant-update-table-t1-in-stored-functiontrigger-because-it-is-already-used-by-statement-which-invoked-this-stored-functiontrigger/

相关文章
相关标签/搜索