在选择之前触发

时间:2013-03-08 07:50:47

标签: mysql select triggers

我有以下触发器声明

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

1 个答案:

答案 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 |更新|删除}