当前位置:网站首页>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 ';边栏推荐
- The idea of Google's "Ai awareness" event this month
- JS ------ Chapter 3 JS cycle
- Shardingsphere database sub database sub table introduction
- MATLAB basic grammar (II)
- Understanding complexity and simple sorting operation
- Use and partial explanation of QDIR class
- Introduction to HLS programming
- Things to study
- Collection of common online testing tools
- JS ------ Chapter II JS logic control
猜你喜欢

Network Security Learning (IV) user and group management, NTFS

背景图和二维码合成

How painful is it to write unit tests? Can you do it

Notes of Teacher Li Hongyi's 2020 in-depth learning series 5

老杜Servlet-JSP

Network Security Learning (V) DHCP

Implementation of cat and dog data set classification experiment based on tensorflow and keras convolutional neural network

凸优化基础知识

百度网盘+Chrom插件

Notes of Teacher Li Hongyi's 2020 in-depth learning series 4
随机推荐
Collection of common online testing tools
关于板载继电器供电不足引起不能吸合的问题
The rule created by outlook mail is invalid. Possible reasons
The laneatt code is reproduced and tested with the video collected by yourself
CA证书制作实战
Some analysis of slow MySQL query
Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK
Salesforce zero foundation learning (116) workflow - & gt; On flow
QT | event system qevent
Is the income of CICC securities' new financial products 6%? I want to open an account and manage money
Let‘s Encrypt
如何创建和管理自定义的配置信息
QT6 with vs Code: compiling source code and basic configuration
Excel文件处理工具类(基于EasyExcel)
[zero basis] SQL injection for PHP code audit
基于Verilog HDL的数字秒表
理财产品可以达到百分之6的,我想要开户买理财产品
WPF uses pathgeometry to draw the hour hand and minute hand
See project code Note 1
Architecture design of multi live shopping mall