有一tb_worker表,它记录的是一些树状结构的人员信息,即是,每条记录代办一个worker,而worker之间可能是树状的上下级关系,现在想在某worker记录的一个字段发生改变时,递归的向上更新所有上级的相关字段,我写的触发器如下:
delimiter $$
create trigger subordinate_publish_amount_trigger
after update on tb_worker for each row
begin
if new.i_subordinate_publish_amount_current_month>old.i_subordinate_publish_amount_current_month THEN
update tb_worker w set w.i_subordinate_publish_amount_current_month=w.i_subordinate_publish_amount_current_month+1,
w.i_subordinate_publish_total_amount=w.i_subordinate_publish_total_amount+1 where w.i_role_id=new.i_superior_id;
end if;
end;
$$
delimiter ;但是,手动更改数据库中i_subordinate_publish_amount_current_month字段后,会报错,说:
Can't update table 'tb_worker' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
是否MySQL有限制,不能在自身表上进行递归触发的?