触发错误 [英] Trigger Error , MySQL

查看:78
本文介绍了触发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我已经研究并没有找到以下问题的解决方法'SQL Error (1442): Can not update table' messages' in stored function / trigger because it is already used by statement Which invoked this stored function / trigger.`

Well, I have researched and have not found a solution to the following problem 'SQL Error (1442): Can not update table' messages' in stored function / trigger because it is already used by statement Which invoked this stored function / trigger. `

我的触发器已创建,仅当我在消息表上运行INSERT时,才会引发此错误,我的触发器是

My trigger is created, only when I run the INSERT on the table of messages, this error is thrown, my trigger is

DELIMITER $$ 
DROP TRIGGER IF EXISTS `onMessage` ;
CREATE TRIGGER `onMessage` BEFORE INSERT ON `messages` FOR EACH ROW 
BEGIN
       UPDATE `users` SET `users`.`messages` = ( `users`.`messages` + 1 ) 
       WHERE `users`.`uid` = NEW.uid ;
       DELETE FROM `messages` WHERE `date` < ( NOW( ) - INTERVAL 1 MINUTE ) ;
END ;
$$
DELIMITER ;

推荐答案

这是触发器使用的限制.

This is a restriction in the use of triggers.

从MySql 文档:

在存储的函数或触发器中,不允许修改调用该函数或触发器的语句已在使用(用于读取或写入)的表.

Within a stored function or trigger, it is not permitted to modify a table that is already being used (for reading or writing) by the statement that invoked the function or trigger.

这篇关于触发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆