在 MySql 中删除触发器抛出错误 1064
尝试运行以下...(MySql 5.5.9)
查询时出现错误(1064):
CREATE TRIGGER clearChat AFTER INSERT ON chat
FOR EACH ROW
BEGIN
DELETE p.* FROM chat p LEFT JOIN (SELECT t.id FROM chat t ORDER BY t.id DESC LIMIT 50) x ON x.id = p.id WHERE x.id IS NULL
END;
错误是:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 5
任何帮助都会很棒。
最后编辑:更新以显示“FOR EACH ROW”和“BEGIN”
I get an error (1064) when attempting to run the following... (MySql 5.5.9)
query:
CREATE TRIGGER clearChat AFTER INSERT ON chat
FOR EACH ROW
BEGIN
DELETE p.* FROM chat p LEFT JOIN (SELECT t.id FROM chat t ORDER BY t.id DESC LIMIT 50) x ON x.id = p.id WHERE x.id IS NULL
END;
the error is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 5
Any assistance would be great.
Last Edit: Updated to show the 'FOR EACH ROW' and 'BEGIN'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
DELETE
之前您缺少FOR EACH ROW
:http://dev.mysql.com/doc/refman/5.1/en/create-trigger.html编辑: 还有更多问题。正确的语法如下:
编辑2:
基于此,我认为根本不允许查询位于触发器中http://dev.mysql.com/doc/refman/5.1/en/faqs-triggers.html#qandaitem-B-5-1-9:
由于您没有使用
OLD
或NEW
,我认为您无法修改chat
,因为触发器是在插入时触发的>聊天
。You're missing
FOR EACH ROW
beforeDELETE
: http://dev.mysql.com/doc/refman/5.1/en/create-trigger.htmlEdit: There are more issues. The correct syntax is below:
Edit 2:
I don't think that query is allowed to be in a trigger at all based on this http://dev.mysql.com/doc/refman/5.1/en/faqs-triggers.html#qandaitem-B-5-1-9:
Since you aren't using
OLD
orNEW
, I don't think you can modifychat
since the trigger is triggered on inserts tochat
.我对以下语句也遇到了同样的问题,即使是这个简化的删除语句,它也总是给我一个语法错误(最初是 DELETE FROM APP_CACHE_VIEW WHERE APP_UID = OLD.APP_UID; ):
如果我更改了 SQL命令如下,然后它起作用了,但我不明白为什么:
I had the same problem with the following statement, it ALWAYS gave me a syntax error on even this simplified delete statement (originally was
DELETE FROM APP_CACHE_VIEW WHERE APP_UID = OLD.APP_UID;
):If I changed the SQL command to the following then it WORKED but I don't understand why: