gpt4 book ai didi

MySQL错误: Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger

转载 作者:行者123 更新时间:2023-11-29 23:19:10 26 4
gpt4 key购买 nike

错误:无法更新存储函数/触发器中的表“tbl”,因为它已被调用此存储函数/触发器的语句使用。

插入代码之前触发:

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

我想创建一个触发器,在每次插入之前检查每一行并删除旧的。

但是当我尝试在此表上添加 ro 时,它给出以下错误

无法更新存储函数/触发器中的表“tbl”,因为它已被调用此存储函数/触发器的语句使用。

这个错误是什么意思?谢谢

最佳答案

相反,我创建了一个事件,并且它工作正常。

SET GLOBAL event_scheduler = ON;
CREATE EVENT IF NOT EXISTS tbl
ON SCHEDULE EVERY 1 MINUTE STARTS NOW()
DO DELETE FROM tbl WHERE ProxyLoggingDate <= DATE_SUB(NOW(), INTERVAL 7 WEEK);

关于MySQL错误: Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27481100/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com