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 即可。