我有程序:
CREATE PROCEDURE channge_max_priority()
BEGIN
update feeds set max_post_priority =
(
select max(feed_posts.priority)
from feed_posts
where feed_posts.feed_id = feed_id
)
where feeds.id = feed_id;
END
我想创建三个触发器:
CREATE TRIGGER feed_post_after_test AFTER INSERT (And update and delete ) ON feed_posts
FOR EACH ROW EXECUTE PROCEDURE change_max_priority();
程序正常工作,但是当我尝试启动触发器时 - 我收到错误:
Error in query (1064): Syntax error near 'PROCEDURE change_max_priority()' at line 2
答案 0 :(得分:1)
您在名称程序中有一个nn
个:
替换:
CREATE PROCEDURE channge_max_priority()
通过
CREATE PROCEDURE change_max_priority()
答案 1 :(得分:0)
尝试更改update语句以使用连接,这应该有效:
update feeds
set max_post_priority = max(feed_posts.priority)
FROM feeds f
INNER JOIN feed_posts fp on feed_posts.feed_id = f.feed_id
Group BY f.feed_id
答案 2 :(得分:-1)
在mysql中,使用CALL
执行过程:
CREATE TRIGGER feed_post_after_test AFTER INSERT (And update and delete ) ON feed_posts
FOR EACH ROW CALL change_max_priority();
我不明白为什么你应该为每一行执行程序,整个feeds
表在一个程序调用中更新。
也不确定过程中的最后where feeds.id = feed_id;
(END
之前)是否正确。