我有以下触发器声明
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//
我尝试按照此处给出的说明http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html但是出现语法错误。我做错了什么?
注意我在SELECT
表上运行了Review
语句,它给出的结果没有任何问题。
编辑:我意识到我在SELECT
之前无法触发,因此决定在应用层处理它。请参阅:http://forums.mysql.com/read.php?99,277396,277692#msg-277692
答案 0 :(得分:1)
trigger_event不能是select trigger_event = {INSERT |更新|删除}
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 |更新|删除}