数据库触发器报错:Error Code: 1442. Can‘t update table in stored function/trigger because...
·
Error Code:1442.Can't update table 'orderdetails' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
- 报错原因(官方):when you insert a record mysql is doing some lock stuff. you can't insert/update/delete rows of the same table where you insert.. because then the trigger would called again and again.. ending up in a recursion
- 官方链接:MySQL :: Re: Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
- 在使用触发器时,执行操作的对象 与 拥有该触发器的表不能为同一张表,否则触发器会不停地进行递归调用
例如在orderdetails中执行delete操作(错误代码):

- 解决办法:触发器作用的表应该是 orders 而不是 orderdetails,将 orderdetails 改为 orders 即可。
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐

所有评论(0)