创建触发器时出现sql错误

时间:2012-06-04 10:23:08

标签: mysql triggers sql-delete

我将此代码输入mysql,但它出错了:


CREATE TRIGGER delete_vote_topic BEFORE DELETE ON vote_topic
  FOR EACH ROW BEGIN
    DELETE FROM vote_option WHERE vote_topic_id = OLD.id;
    DELETE FROM vote_option_votes WHERE vote_topic_id = OLD.id;
  END;

错误是:

  

#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第3行的''附近使用正确的语法

有人知道我做错了吗?

1 个答案:

答案 0 :(得分:2)

尝试使用分隔符

delimiter |

CREATE TRIGGER delete_vote_topic BEFORE DELETE ON vote_topic 
FOR EACH ROW 
BEGIN 
     DELETE FROM vote_option 
     WHERE vote_topic_id = OLD.id; 
     DELETE FROM vote_option_votes 
     WHERE vote_topic_id = OLD.id; 
END;

|