当前位置:网站首页>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 :
边栏推荐
- [IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games
- Finally got byte offer, 25-year-old inexperienced experience in software testing, to share with you
- New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
- 机器学习基本概念
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- error: . repo/manifests/: contains uncommitted changes
- II Basic structure of radio energy transmission system
- Volume compression, decompression
- Learn C language from scratch day 025 (maze)
- Parted command
猜你喜欢
Three core problems of concurrent programming
Exclusive delivery of secret script move disassembly (the first time)
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
企业应该选择无服务器计算吗?
6-3漏洞利用-SSH环境搭建
Feature extraction and detection 16 brisk feature detection and matching
TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
Raspberry pie 4B learning notes - IO communication (1-wire)
What are the affordable Bluetooth headsets? Student party parity Bluetooth headset recommendation
随机推荐
【LeetCode 43】236. The nearest common ancestor of binary tree
Docker安装Oracle_11g
There are spaces in the for loop variable in the shell -- IFS variable
牛客网——华为题库(51~60)
Look at the industrial Internet from a new perspective and seek the correct ways and methods of industrial Internet
Android: how can golden nine and silver ten squeeze into the first-line big factories from small and medium-sized enterprises? The depth of interview questions in large factories
技术大佬准备就绪,话题C位由你决定
卷积神经网络(包含代码与相应图解)
Makefile simple induction
Number of palindromes in C language (leetcode)
Android high frequency network interview topic must know and be able to compare Android development environment
uTools
【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
matlab 使用 resample 完成重采样
Luogu p1775 stone merger (weakened version)
电子协会 C语言 1级 33 、奇偶数判断
分卷压缩,解压
This is the form of the K-line diagram (pithy formula)
Leetcode, 3 repeatless longest subsequence
浅浅了解Servlet