I have the following trigger statement
DELIMITER //
CREATE TRIGGER rating
BEFORE SELECT
ON `clinic`
FOR EACH ROW
BEGIN
SET NEW.OLD.`rate` = (SELECT AVG(`rate`) FROM `Review` WHERE `Clinic_id` = NEW.OLD.`id`);
END//
I tried to follow the instructions given here http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html but getting syntax error. What am I doing wrong?
NB I have run the SELECT
statement on Review
table and it gives result without any problem.
Edited: I realized that I can't have a trigger before SELECT
and therefore decided to handle that on the application layer. See this: http://forums.mysql.com/read.php?99,277396,277692#msg-277692
trigger_event can not be a select trigger_event = { INSERT | UPDATE | DELETE }
CREATE
[DEFINER = { user | CURRENT_USER }]
TRIGGER trigger_name
trigger_time trigger_event
ON tbl_name FOR EACH ROW
trigger_body
trigger_time: { BEFORE | AFTER }
trigger_event: { INSERT | UPDATE | DELETE }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With