Mysql在insert触发器里如何update当前数据

来源:互联网 发布:手机淘宝实人认证在哪 编辑:程序博客网 时间:2024/05/21 02:48

create trigger update_areabeginupdate workset new.area = (select area from `unit` left join `group` on unit.id=`group`.unitid where `group`.id = new.groupId ) where id = new.id;end;


在insert数据时想更新本条记录出现错误,Can't update table 'work' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.原因是会造成循环的调用。

应该使用set进行调用

create trigger update_areabegin set new.area = (select area from `unit` left join `group` on unit.id=`group`.unitid where `group`.id = new.groupId );end




原创粉丝点击