MySQL 触发器抛出错误 1064
MySQL trigger throws error 1064
首先,我知道有很多相同类型的问题,但它们并没有解决我的问题!
如果给定的 2 列集合超过 10 行,我想删除最旧的行。我的触发器如下所示:
DELIMITER //
CREATE TRIGGER TEST_TRIGGER
AFTER INSERT
ON table1
FOR EACH ROW
BEGIN
SELECT COUNT(*)
INTO @Tcount
FROM table1
WHERE columnA = NEW.columnA
AND columnB = NEW.columnB;
IF @Tcount > 10 THEN
DELETE FROM table1
WHERE id in (select * from (select MIN(id) from table1 where columnA = NEW.columnA and columnB = NEW.columnB) as t);
END IF;
END;
//
DELIMITER;
我在文件中有触发器,但在执行时抛出错误。完整的错误是
ERROR 1064 (42000) at line 25: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER' at line 1
第 25 行是具有 DELIMITER;
的最后一行
我的 table 看起来像这样:
CREATE TABLE `table1` (
`columnA` varchar(255) NOT NULL,
`columnB` varchar(255) NOT NULL,
`Version` varchar(255) NOT NULL,
`Build` int(11) DEFAULT NULL,
`Date` varchar(255) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
)
即使在抛出错误后也会添加触发器。但是,当我将第 11 个条目(对于 columnA 和 columnB 的给定组合)添加到 table 时,出现以下错误:
ERROR 1442 (HY000): Can't update table 'table1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
触发器中的 select 和 delete 语句在单独执行时没问题,当然具有适当的值。
MySQL版本5.5.46
如果有任何更正/建议,我将不胜感激。
我会去掉结束后的分号。
... END | DELIMITER ;
试试看。
此参考可能对您有所帮助:mysql delimiter error
首先,我知道有很多相同类型的问题,但它们并没有解决我的问题!
如果给定的 2 列集合超过 10 行,我想删除最旧的行。我的触发器如下所示:
DELIMITER //
CREATE TRIGGER TEST_TRIGGER
AFTER INSERT
ON table1
FOR EACH ROW
BEGIN
SELECT COUNT(*)
INTO @Tcount
FROM table1
WHERE columnA = NEW.columnA
AND columnB = NEW.columnB;
IF @Tcount > 10 THEN
DELETE FROM table1
WHERE id in (select * from (select MIN(id) from table1 where columnA = NEW.columnA and columnB = NEW.columnB) as t);
END IF;
END;
//
DELIMITER;
我在文件中有触发器,但在执行时抛出错误。完整的错误是
ERROR 1064 (42000) at line 25: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER' at line 1
第 25 行是具有 DELIMITER;
我的 table 看起来像这样:
CREATE TABLE `table1` (
`columnA` varchar(255) NOT NULL,
`columnB` varchar(255) NOT NULL,
`Version` varchar(255) NOT NULL,
`Build` int(11) DEFAULT NULL,
`Date` varchar(255) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
)
即使在抛出错误后也会添加触发器。但是,当我将第 11 个条目(对于 columnA 和 columnB 的给定组合)添加到 table 时,出现以下错误:
ERROR 1442 (HY000): Can't update table 'table1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
触发器中的 select 和 delete 语句在单独执行时没问题,当然具有适当的值。
MySQL版本5.5.46
如果有任何更正/建议,我将不胜感激。
我会去掉结束后的分号。
... END | DELIMITER ;
试试看。
此参考可能对您有所帮助:mysql delimiter error