MySQL错误:无法更新存储函数/触发器中的表'tbl',因为调用该存储函数/触发器的语句已使用该表 [英] MySQL Error: Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
问题描述
错误:无法更新存储函数/触发器中的表'tbl',因为调用该存储函数/触发器的语句已使用该表。
Error: Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
之前触发插入代码:
CREATE DEFINER=`root`@`localhost` TRIGGER `opcdls`.`tblTrigger`
BEFORE INSERT ON `tbl` FOR EACH ROW
BEGIN
DELETE FROM tbl
WHERE ProxyLoggingDate <= DATE_SUB(NOW(), INTERVAL 7 WEEK);
END
我想创建一个触发器,在每次插入之前检查每一行并删除
I want to create a trigger where before each insert check each row and delete the old.
但是当我尝试在此表上添加ro时,出现以下错误
But when I try to add a ro on this table it gives me below error
可以吗? t更新存储函数/触发器中的表 tbl,因为调用该存储函数/触发器的语句已使用该表。
Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
此错误是什么意思?
谢谢
What does this error mean? Thanks
推荐答案
代替触发器,我创建了一个事件,并且它正常工作。
Instead a trigger i create a event and it is working properly.
SET GLOBAL event_scheduler = ON;
创建事件(如果不存在)tbl
每1分钟立即开始计划()
从tbl删除ProxyLoggingDate< = DATE_SUB(NOW(),间隔7周);
这篇关于MySQL错误:无法更新存储函数/触发器中的表'tbl',因为调用该存储函数/触发器的语句已使用该表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!