MySql 添加触发器后添加不了数据也更新不了数据,然后报错。
那位大侠解决下。
was an drror while applying sql script to the database
信息如下 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
--转自