Anshul Sahni
Anshul Sahni

Reputation: 666

What is the error in following mysql query for making trigger

Please can someone explain what is the syntax error in the following mysql command to create the trigger

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;

Upvotes: 0

Views: 37

Answers (1)

Rahul
Rahul

Reputation: 77876

Not sure about any error but the below line to set @ansh

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

should be

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

Also, don't think this declare statement needed declare @ansh INT(2);

Upvotes: 1

Related Questions