以下mysql查询生成触发器的错误是什么

时间:2014-06-04 19:34:13

标签: mysql triggers insert

请有人解释以下mysql命令中的语法错误是什么,以创建触发器

create trigger comment_on_network 
after insert on network_comments
for each row begin 
declare @ansh INT(2); 
set @ansh=(select count(*) from network_comments where
network_comments.network_id=NEW.network_id);
update networks set networks.no_of_comments=@ansh where
networks.network_id=NEW.network_id;
END;

1 个答案:

答案 0 :(得分:1)

不确定是否有任何错误,但下面的行设置@ansh

set @ansh=(select count(*) from network_comments where
network_comments.network_id=NEW.network_id);

应该是

set @ansh := (select count(*) from network_comments where
network_comments.network_id=NEW.network_id);

另外,不要认为此声明语句需要declare @ansh INT(2);