当前位置:网站首页>SQLite database operation
SQLite database operation
2022-07-24 23:27:00 【Hanyang Li】
1. Table creation SQL
/**
CREATE TABLE -- Table creation
IF NOT EXISTS -- Determine whether the data table exists , If there is , No more table creation SQL
'T_Person' -- Table name
(
Field 1 INTEGER( Integers )/REAL( decimal )/TEXT( character string )/BLOB( binary data - Usually not saved in the database )
NOT NULL Not allowed to be empty , The primary key must have content
PRIMARY KEY Primary key
AUTOINCREMENT Automatic growth
, Distinguish each field , The last field doesn't need to be ‘,’
Field 2 type
...
)
Use :
1. source , You can copy and paste
2. Single quotation marks are recommended , It can avoid translating in the program
3.IF NOT EXISTS It needs to be added separately , In order to ensure SQL Statements can be repeatedly executed !
4. Every SQL At the end of the statement , It is suggested to add a ';' It means a complete SQL end
*/
CREATE TABLE IF NOT EXISTS 'T_Person' (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT,
"age" INTEGER,
"height" NUMBER
);2. Insert SQL
/**
INSERT INTO ‘ Table name ’
( Field 1, Field 2, ...)
VALUES
( value 1, value 2, ...)
Be careful :
1. The order of fields and values must be consistent
Tips :
SQLite Data types are essentially indistinguishable , Save whatever you want , When defining the table structure , The specified type is just decoration
It is recommended to store by type
*/
INSERT INTO T_Person
(name,age,height)
VALUES
(' Little love ',22,1.55);3. Delete SQL
/**
DELETE FROM ' Table name '
WHERE Primary key = id
Be careful :
Delete statements must be written WHERE! Otherwise, all data will be deleted !
If the specified condition does not exist ,SQL Will execute , But the number of affected lines is 0
*/
DELETE FROM T_Person
WHERE id = 2000;4. to update SQL
/**
UPDATE ‘ Table name ’
SET
Field 1 = ‘ A string value 1’,
Field 2 = value 2
...
WHERE( Conditions )
Primary key = id;
Tips :
Be sure to write conditions , Otherwise, all records will be modified
If the specified condition does not exist ,SQL Will execute , But the number of affected lines is 0
*/
UPDATE T_Person SET name = ' Lao Wang ',age = 28, height = 1.76
WHERE id = 10005. Inquire about SQL
-- Check all records , however : It is not recommended to write * wildcard , Reading the code directly cannot know the content returned by the query
-- It can be used in testing , In program code , Not recommended
SELECT * FROM T_Person;
-- Recommended for development , Easy to read
SELECT id, name, height, age FROM T_Person;
-- Statistics query
SELECT COUNT(*) FROM T_Person;
-- Specify conditional statistics query
SELECT COUNT(*) FROM T_Person WHERE height > 1.7;
-- Ask the oldest person
-- Application scenarios : The highest value of query experience , People who recently joined ...
SELECT MAX(age) FROM T_Person;
-- Paging function
-- LIMIT Start with the record ( The starting number is : 0), The number of record rows returned
SELECT id, name, height, age FROM T_Person
LIMIT 0, 2;
-- LIMIT And conditional instructions WHERE Use a combination of , You can easily make paging function
SELECT id, name, height, age FROM T_Person
WHERE id >= 8
LIMIT 2;
-- Sorting function , Default ascending order ASC / Descending DESC
-- Sorting is based on specified conditions , Sort from left to right
SELECT id, name, height, age FROM T_Person
ORDER BY name DESC, age ASC;
-- Fuzzy query
-- % Can match anything
-- % Content % It means that as long as the content appears , Will be searched out
-- logic AND OR NOT
SELECT id, name, height, age FROM T_Person
WHERE (name LIKE '% king %' AND age > 18) OR name LIKE ' Zhang dada ';边栏推荐
- ES6 adds -iterator traversal, for..Of loop
- Solve the problem that JSP cannot use session.getattribute()
- 痞子衡嵌入式:MCUXpresso IDE下将源码制作成Lib库方法及其与IAR,MDK差异
- Excel文件处理工具类(基于EasyExcel)
- 关于板载继电器供电不足引起不能吸合的问题
- 新手哪个证券开户最好 开户最安全
- The idea of Google's "Ai awareness" event this month
- 生成式对抗网络的效果评估
- Talk about how redis handles requests
- Some analysis of slow MySQL query
猜你喜欢

Notes of Teacher Li Hongyi's 2020 in-depth learning series 6
![[1184. Distance between bus stops]](/img/dd/3437e6a14ac02dac01c78b372a5498.png)
[1184. Distance between bus stops]

Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK

认识复杂度和简单排序运算

Network Security Learning (V) DHCP

老杜Servlet-JSP
WPF uses pathgeometry to draw the hour hand and minute hand

Go基础笔记_4_map

Convert a string to an integer and don't double it

Paper notes: accurate causal influence on discrete data
随机推荐
Org.json Jsonexception: what about no value for value
中金证券新课理财产品的收益有百分之六吗?我想要开户理财
Salesforce zero foundation learning (116) workflow - & gt; On flow
Qt | 事件系统 QEvent
Collection of common online testing tools
ES6 adds -iterator traversal, for..Of loop
Pointrender parsing
Notes of Teacher Li Hongyi's 2020 in-depth learning series 3
Simple message queue implementation nodejs + redis =mq
The rule created by outlook mail is invalid. Possible reasons
burp从溯源到反制思路
HTB-Aragog
痞子衡嵌入式:MCUXpresso IDE下将源码制作成Lib库方法及其与IAR,MDK差异
聊聊 Redis 是如何进行请求处理
The specified data is grouped and the number of repetitions is obtained in Oracle
CA证书制作实战
Notes of Teacher Li Hongyi's 2020 in-depth learning series 7
Talk about how redis handles requests
Trinitycore worldofwarcraft server - registration website
Entity service is an anti pattern