当数据插入同一个表格时,我使用触发器更新表格!但是,当我在该表中插入数据时,我得到错误
ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG: Can't update table
这是什么意思?
触发COde:
create trigger update_owners_leaving_time
AFTER INSERT ON cc_owners_queries
FOR EACH ROW BEGIN
update cc_owners_queries set leaving_time = query_time + INTERVAL leaving_in MINUTE , trigger_updated = 1 where trigger_updated !=1;
END
错误:
Error: ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG: Can't update table 'cc_owners_queries' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
答案 0 :(得分:0)
你必须做点什么:
create trigger update_owners_leaving_time
AFTER INSERT ON cc_owners_queries
FOR EACH ROW BEGIN
IF NEW.trigger_updated != 1 THEN
set NEW.leaving_time = NEW.query_time + INTERVAL NEW.leaving_in MINUTE;
SET NEW.trigger_updated = 1;
END IF;
END
您不必说您需要更新当前表格。你循环遍历行..那行将成为目标。
更多信息:http://dev.mysql.com/doc/refman/5.6/en/trigger-syntax.html