我正在尝试编写一个触发器,以便在表达到限制时删除一定数量的行。这就是我目前所拥有的:
IF (SELECT COUNT(rowa) FROM tableA ) > 10
THEN
DELETE FROM table WHERE dateinsert IN (
SELECT * FROM (
SELECT dateinsert FROM tableA ORDER BY dateinsert ASC limit 1
) AS P
)
end if;
pypmyadmin提示我有语法错误。
答案 0 :(得分:1)
您的sql DELETE 语句中存在语法错误。您无法使用关键字表格。 以下是一个例子。
我已在删除声明中将表格更改为 tableA 。
IF (SELECT COUNT(rowa) FROM tableA ) > 10 THEN
DELETE FROM tableA WHERE dateinsert IN
(SELECT dateinsert FROM
(SELECT dateinsert FROM tableA ORDER BY dateinsert ASC limit 1) AS tmp1);
END IF;