我曾尝试在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):语法错误接近' 4013834123456 ORDER BY id LIMIT 1 END END IF END'在第6行
我刚尝试过;在END'但然后出现更多错误...... 我使用Adminer 4.1.0 MySQL数据库! 求救!
UPDATE,现在可以使用分隔符:
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;
答案 0 :(得分: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 ;