在altervista中触发mysql

时间:2016-08-07 10:13:00

标签: mysql triggers

我在altervista上使用mysql并且我执行了此触发器,但是当我尝试它时,#34;#1064 - 您的SQL语法出错了;查看与您的MySQL服务器版本相对应的手册,以获得在''附近使用的正确语法。在第5行",帮助请

CREATE TRIGGER  increase
AFTER INSERT ON tableA
FOR EACH ROW
BEGIN
    DECLARE counter INTEGER; <---- line 5

    SELECT count(*)
    INTO counter
    FROM tableC;

    IF(counter ==  0) THEN
        UPDATE tableB
        SET num = num + 1;
    END IF;
END

1 个答案:

答案 0 :(得分:0)

你需要change the delimiter - MySQL正在看第一个&#34 ;;&#34;作为CREATE TRIGGER语句的结尾。

试试这个:

/* Change the delimiter so we can use ";" within the CREATE TRIGGER */
DELIMITER $$

CREATE TRIGGER increase
BEFORE INSERT ON tableA
FOR EACH ROW BEGIN
     DECLARE counter INTEGER;  

    SELECT count(*)
     INTO counter
     FROM tableC;

     IF(counter ==  0) THEN
        UPDATE tableB
       SET num = num + 1;
     END IF;
END$$
/* This is now "END$$" not "END;" */

/* Reset the delimiter back to ";" */
DELIMITER ;