插入前创建 Mysql 个触发器

Create Mysql Trigger before Insert

我试过对 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;

您忘记了使用反引号转义 table 名称 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 ;