当前位置:网站首页>How SQLite limits the total number of data in a table
How SQLite limits the total number of data in a table
2022-06-12 07:55:00 【Ruoyun Liufeng】
1、 Do it regularly :
DELETE FROM table where _id NOT IN (SELECT _id from table ORDER BY insertion_date DESC LIMIT 50)
2、 Or build a 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;2.1 explain :
a. The trigger condition :
INSERT ON _table WHEN (select count(*) from _table)>50
When inserting a table, check whether the total number of entries is greater than 50, If it is greater than 50 Then start .
b. Delete data
DELETE FROM _table WHERE _table._id IN (SELECT _table._id FROM _table ORDER BY _table._id limit (select count(*) -50 from _table ));
1. Find out what you want to delete id:DELETE FROM _table WHERE _table._id IN
2. Delete from the earliest , Save only the latest 50 strip : Limit the number of queries ,limit (select count(*) -50 from _table ). Yes id Sort , Of course, it can also be sorted by time .
Reference resources :sqlite How to limit the total number of data in a table _love_android_2011 The column -CSDN Blog
边栏推荐
- Leetcode notes: Weekly contest 275
- Summary of machine learning + pattern recognition learning (IV) -- decision tree
- [tutorial] deployment process of yolov5 based on tensorflow Lite
- 2021.10.24-25 scientific research log
- Summary of semantic segmentation learning (II) -- UNET network
- The project file contains toolsversion= "14.0". This toolset may be unknown or missing workarounds
- [redistemplate method details]
- Voice assistant -- Qu -- query error correction and rewriting
- Topic 1 Single_Cell_analysis(4)
- Utilize user behavior data
猜你喜欢

谋新局、促发展,桂林绿色数字经济的头雁效应

Generalized semantic recognition based on semantic similarity

Chapter 4 - key management and distribution

Rich dad, poor dad Abstract

Voice assistant -- vertical class perpetual motion machine -- automated iteration framework

The project file contains toolsversion= "14.0". This toolset may be unknown or missing workarounds

Utilize user behavior data

Process terminated

Topic 1 Single_Cell_analysis(2)

The computer is connected to WiFi but can't connect to the Internet
随机推荐
ECMAScript6面试题
最新hbuilderX编辑uni-app项目运行于夜神模拟器
Leetcode notes: biweekly contest 79
Interview questions on mobile terminal, Android and IOS compatibility
Compiling principle on computer -- functional drawing language (IV): semantic analyzer
Rnorm function of R language generates positive distribution data, calculates descriptive statistical summary information of vector data using sum function of epidisplay package, and visualizes ordere
Symfony 2: multiple and dynamic database connections
Cold start problem of recommended system
Web page performance optimization interview questions
[RedisTemplate方法详解]
Topic 1 Single_ Cell_ analysis(4)
Generalized semantic recognition based on semantic similarity
连接数据库却无法修改数据
Summary of semantic segmentation learning (II) -- UNET network
2021.11.2 scientific research log
Solve mapper duplication problem in reverse engineering
Summary of machine learning + pattern recognition learning (VI) -- feature selection and feature extraction
Bi skills - beginning of the month
Logistic regression
Compiling principle on computer -- function drawing language (III): parser