我创建了一个 MySQL 触发器,旨在每次添加新记录时清除最旧的记录:
CREATE DEFINER = `root`@`localhost` TRIGGER `cleanRecords` BEFORE INSERT ON `Records`
FOR EACH
ROW BEGIN
SELECT COUNT( * )
INTO @cnt
FROM cla.Records;
IF @cnt >=1000 THEN DELETE FROM cla.Records ORDER BY createdDate DESC LIMIT 1 ;
END IF ;
END
期望保持 1000 条最新记录不被连续操作。该操作已确认可以正常工作,但此触发器不是。我误解了触发器还是这个只是写错了?