当前位置:网站首页>SQLite 3 of embedded database
SQLite 3 of embedded database
2022-07-02 01:43:00 【xuechanba】
Basic concepts of database
data (Data)
Be able to input into the computer and be programmed by the computer Identify and deal with A collection of information .
database (DataBase)
The database is in Database management system Under management and control , Store in On the storage medium Data set for .
Database management system (DBMS)
Common database management system
Large database management system
Oracle
IBM Of DB2
Medium sized database management system
Server It is a database product developed by Microsoft , Main support Windows platform .
Small database management system
MySQL
Based on embedded database management system
SQLite、Firebird、eXtremeDB
SQLite Basics
Basic overview
SQLite Is a lightweight open source embedded database , from D.Richard Hipp stay 2000 Released in .SQLite The source code for is C, Completely open , Widely used in consumer electronics 、 Medical care 、 Industrial control 、 Military and other fields . Through this database software , We can create, add, delete, modify and check the database .
characteristic
(1) Zero configuration , No need to install and manage configuration
(2) Stored on disk as a file .
(3) Strong portability : Can support all kinds of 32 Bit and 64 Hardware platform of bit system , Can also be in Windows、Linux、BSD、Mac OS、Solaries And other software platforms .
(4) Support database size to 2TB.
(5) Small enough , The whole source code is roughly 3 Wan line code ,250KB.
The video tutorial link is as follows :https://www.bilibili.com/video/BV1Li4y1f7ho?p=2.
SQLite 3 Installation

sudo apt-get install sqlite3
sqlite3 -version
Be careful :sqlite3 Key words of ( Including data types and commands ), Case insensitive .
SQLite 3 Data types in

The concept of table

Use sqlite3 Create a database file
1、 Create database

Suppose here , We want to create a stu.db Library file
You can enter
sqlite3 stu.db
after , You enter command line mode , As shown in the figure below .
After input .quit after , Will exit command line mode , At same time, current folder has not been created stu.db The file of , This is because we did not edit or operate this database file .
This is the time , We can use .table Let's operate it , And then you type in .quit And view the contents under the current folder . Take a look .
Of course use .table To create a database file with empty tables .
Use sqlite3 Complete the operation of the table
1、 Create table

Be careful : Enter a semicolon at the end to indicate the end .
2、 Create table common field properties

The attributes of the same field can be different .
So-called autoincrement ( Self increasing ), That is to say , Assuming that the current field is not specified , It will automatically increase according to the previous field value . such as , The value of the previous field is 1, If the current field is not specified , Its value will be 2.
Here is a demonstration , use first sqlite3 To create a table , The content of the table is students , Two fields are set here , One is id, One is the student's name , among ,id The attribute of is the primary key , The data type is integer , The attribute of student name is not empty , The data type is text string .
Use command
sqlite3 stu.db
To open the database file .
CREATE TABLE stu(id INTEGER primary key AUTOINCREMENT,
name TEXT not null);
How to check the table we just created ?
have access to .table Let's see what we have built .
How to check the contents of the table , Use “.schema + Table name ”.
3、 Insert elements
4、 View the fields of the elements in the table
5、 filter

It is not necessary to write all the field names in the table at one time , Because the attributes of some fields are self increasing .
Field name 1 Corresponding to the field value 1, Field name 2 Corresponding to the field value 2.
Now try to insert several student information into the table , As shown in the figure below .
Be careful , Correct and wrong writing .
1、 Data of text string type can use single quotation marks or double quotation marks , You can't do without .
Write it correctly :
INSERT INTO stu(id,name)values(202201,' Zhang San ');
INSERT INTO stu(id,name)values(202202," Li Si ");
Wrong writing :
INSERT INTO stu(id,name)values(202201, Zhang San );
2、 Some field names can be left blank ( For example, the attribute of this field is set to self increment ), But pay attention to consistency , It doesn't say , Don't write in the back , It says , It should also be written later ( Cannot be empty , Don't even add a comma ).
Write it correctly :
INSERT INTO stu(name)values(" Wang Wu ");
Wrong writing :
INSERT INTO stu(id,name)values(," Wang Wu ");
Error: near ",": syntax error
Let's try again to view the student information just inserted into the table , Use here select Order to proceed , As shown in the figure below .
select id,name FROM stu;
The output is as follows :
here , If we still want to put the header ( Field ) Print it out , You have to enter the command before querying
.header on
Look at the picture below .
Besides , We can also use where Add filter .
Be careful , The equal condition is represented by a “=”.
6、 Modifying elements
7、 Remove elements

1、 When modifying the elements in the table , If you do not specify the filter criteria , It will change the values of all fields in the table that meet the conditions you want to modify into the values of the fields you want to modify .
Under the demo : In the table will id = 202201 Of name and id Change the field to ‘ A passer-by ’ and 202006.
UPDATE stu SET name=' A passer-by ',id=202006 WHERE id=202201;
Look at the modified results :
Let's demonstrate again : In the table will id = 202006 Delete the row of from the table .
DELETE FROM stu where id=202006;
Look at the result after deletion :
边栏推荐
- II Basic structure of radio energy transmission system
- matlab 使用 resample 完成重采样
- Matlab uses resample to complete resampling
- Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months
- Using tabbar in wechat applet
- [Maya] the error of importing Maya into Metahuman
- Design and implementation of radio energy transmission system
- Based on configured schedule, the given trigger will never fire
- Private project practice sharing [Yugong series] February 2022 U3D full stack class 009 unity object creation
- How can I batch produce the same title for the video?
猜你喜欢

PR second training

学习笔记3--高精度地图关键技术(上)
![[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface](/img/c9/3fe8693629a8452dcfdb4349ddee0d.png)
[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface

现货黄金分析的技巧有什么呢?

What is AQS and its principle

Exclusive delivery of secret script move disassembly (the first time)

ES6 new method of string

The smart Park "ZhongGuanCun No.1" subverts your understanding of the park

We should make clear the branch prediction

Learn about servlets
随机推荐
并发编程的三大核心问题
Data visualization in medical and healthcare applications
Volume compression, decompression
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
Learning note 3 -- Key Technologies of high-precision map (Part 1)
Ks006 student achievement management system based on SSM
1217 supermarket coin processor
GL Studio 5 installation and experience
SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
Luogu p1775 stone merger (weakened version)
微信小程序中使用tabBar
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
Penser au jeu 15: penser au service complet et au sous - service
卷积神经网络(包含代码与相应图解)
Quatre stratégies de base pour migrer la charge de travail de l'informatique en nuage
uTools
Laravel artisan common commands
It's already 30. Can you learn programming from scratch?
Electronic Society C language level 1 32, calculate the power of 2