mysql 触发器查询语法错误
所以我有以下查询:
CREATE TRIGGER `before_delete`
BEFORE DELETE ON `abc` FOR EACH ROW
BEGIN
DELETE FROM def WHERE OLD.id = objID1 OR OLD.id = objID2;
DELETE FROM ghi WHERE OLD.id = objID;
END;
但是mysql抱怨第1行'END'附近有语法错误....
我做错了什么?
so I have the following query:
CREATE TRIGGER `before_delete`
BEFORE DELETE ON `abc` FOR EACH ROW
BEGIN
DELETE FROM def WHERE OLD.id = objID1 OR OLD.id = objID2;
DELETE FROM ghi WHERE OLD.id = objID;
END;
but then mysql complains that there's syntax error near 'END' at line 1....
what did I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
DELIMTIER
技巧在过程块中包含多个语句。否则它无法区分过程的结束和其中语句的结束。在 文档 页面上,有一个使用分隔符关键字。为了省去您转到该页面并四处查看的麻烦,我认为这可以解决它:
You need to make use of the
DELIMTIER
trick to include multiple statements in a procedure block. Otherwise it can't tell the difference between the end of your procedure and the end of statements inside it. On the documentation page, there is an example using the delimiter keyword.To save you the trouble of going to that page and looking around, I think this will fix it: