简体   繁体   中英

mysql trigger delete on insert syntax error

I am trying to write a trigger to remove a certain number of rows when the table hits a limit. This is what I have currently:

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 prompt that i have a syntax error.

You have syntax error in your sql DELETE statement. You cannot use the keyword table . Below is an example.

I have changed table to tableA in the delete statement.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM