2

我试图在Adminer 上创建一个MYSQL 触发器,但它不起作用。这是我的代码:

    CREATE TRIGGER handle100kRows BEFORE INSERT ON `4013834123456`
FOR EACH ROW
BEGIN

    IF (SELECT COUNT(*) FROM `4013834123456`) = "100000" THEN BEGIN
        DELETE FROM 4013834123456 ORDER BY id LIMIT 1
    END
    END IF

END;

出现以下错误:(1064):(1064):第6行'4013834123456 ORDER BY id LIMIT 1 END END IF END'附近的语法错误

我刚刚尝试过;在 END 上,但随后出现更多错误...我使用 Adminer 4.1.0 和 MySQL 数据库!谢谢帮助!

更新,现在可以使用分隔符:

delimiter |
CREATE TRIGGER handle100kRows BEFORE INSERT ON `4013834123456`
FOR EACH ROW
BEGIN
    IF (SELECT COUNT(*) FROM `4013834123456`) = "100000" THEN
        DELETE FROM `4013834123456` ORDER BY id LIMIT 1;
    END IF;
END;
delimiter;
4

1 回答 1

2

您忘记了4013834123456用反引号转义表名。

你也有end太多了。

delimiter |
CREATE TRIGGER handle100kRows BEFORE INSERT ON `4013834123456`
FOR EACH ROW
BEGIN
    IF (SELECT COUNT(*) FROM `4013834123456`) = "100000" THEN
        DELETE FROM `4013834123456` ORDER BY id LIMIT 1;
    END IF;
END
|
delimiter ;
于 2015-01-20T07:45:02.053 回答