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

荒凉一梦 提交于 2020-01-25 15:50:23

问题


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

Trigger before insert code:

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.

But when I try to add a ro on this table it gives me below error

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


回答1:


Instead a trigger i create a event and it is working properly.

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);



来源:https://stackoverflow.com/questions/27481100/mysql-error-cant-update-table-tbl-in-stored-function-trigger-because-it-is-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!