SQLite笔记.md

1、第一种方式,定期执行

DELETE FROM table where _id NOT IN (SELECT _id from table ORDER BY insertion_date DESC LIMIT 50)

2、第二种方式,建立trigger

CREATE TRIGGER delete_till_50 INSERT ON _table WHEN (select count(*) from _table)>50 
BEGIN
    DELETE FROM _table WHERE _table._id IN  (SELECT _table._id FROM _table ORDER BY _table._id limit (select count(*) -50 from _table ));
END;

你可能感兴趣的:(SQLite笔记.md)