我是靠谱客的博主 缓慢毛巾,这篇文章主要介绍触发器在插入时更新此条新记录 错误it is already used by statement which invoked this stored functiontrigger的解决方法,现在分享给大家,希望可以做个参考。
问题:
create trigger InsertUser
begin
update users
set user_power='[resource]'
where user_id=new.user_id;
end;
当触发器执行过程中出现了错误:我使用的是Mysql5.0
Can't update table 'users' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
请问这里是怎么回事?
解决方法:
如果你在触发器里面对刚刚插入的数据进行了 insert/update, 则出现这个问题。因为会造成循环的调用.
应该使用set操作,而不是在触发器里使用 update,比如
create trigger InsertUser
begin
set new.user_power='[resource]'
end;
另外这里必须在插入之前来执行该触发器。
最后
以上就是缓慢毛巾最近收集整理的关于触发器在插入时更新此条新记录 错误it is already used by statement which invoked this stored functiontrigger的解决方法的全部内容,更多相关触发器在插入时更新此条新记录内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复