Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trigger before select

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

like image 685
mavili Avatar asked Sep 11 '25 15:09

mavili


1 Answers

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 }

like image 196
Lhoussin Avatar answered Sep 13 '25 05:09

Lhoussin