0

我在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 行的 '' 附近使用正确的语法

有人知道我在做什么错吗?

4

1 回答 1

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;

|
于 2012-06-04T10:26:19.780 回答