当前位置:网站首页>QT database learning notes (I) basic concepts of database
QT database learning notes (I) basic concepts of database
2022-06-11 02:02:00 【Penguins on the volcano】
List of articles
QT For other articles, please click here : QT Learning notes

One 、 Concept
● database DB(DataBase)
It's the warehouse where data is stored , Its characteristic is that the data is organized according to the data model , Is highly structured , It can be shared by multiple users and has certain security .
● Database management system DBMS(DataBase Management System)
It is a database management system software located between the user application and the operating system , Its main function is to organize 、 Storing and managing data , Efficiently access and maintain data , frequently-used DBMS Yes Oracle、Microsoft SQL Server and MySQL etc. .
● What is? SQL Language ?
Structured query language (Structured Query Language,SQL) Is a standard language for relational database operations ,
● SQL The composition of the three parts
1)、 Data definition language (Data Description Language,DDL), Data definition language DDL Used to create 、 Delete 、 Modify various objects in the database ----- surface 、 View 、 Indexes 、 A synonym for 、 Clustering, etc
Create database : Create database
Alter database : modify the database
Create table : Create new table
Alter table : change ( change ) Database table
Drop table : Delete table
Create index : Create index ( The search button )
Drop index : Delete index
2)、 Data manipulation language (Data Manipulation Language,DML), Used to manipulate various objects in the database , Retrieve and modify data
Select : Getting data from a database table
Update : Update the data in the database
Delete : Delete data from the database table
Insert into : Insert data into the database
3)、 Data control language (Data Control Language,DCL) For safety management , Determine which users can view or modify data in the database
① to grant authorization
GRANT: to grant authorization
② Roll back
ROLLBACK [WORK] TO [SAVEPOINT]: Go back to a certain point .
SQL>ROLLBACK; The rollback command returns the database state to the last committed state .
③ Submit
COMMIT [WORK]: Submit .
● Explicitly commit , use COMMIT The commit done directly by the command is an explicit commit .
SQL>COMMIT;
● Implicitly submit , use SQL The commit done indirectly by the command is an implicit commit .
ALTER,AUDIT,COMMENT,CONNECT,CREATE,DISCONNECT,DROP,EXIT,GRANT,NOAUDIT,QUIT,REVOKE,RENAME.
● Automatic submission , If the AUTOCOMMIT Set to ON, Then insert 、 modify 、 After the delete statement is executed , The system will automatically submit , This is auto submit .
SQL>SET AUTOCOMMIT ON;
● Database table
A database usually contains one or more tables . Each table has a name identifier , Table contains records with data ( That's ok ), as follows :
● QtSql Module hierarchy 
● Qt5 Database driven
Qt SQL The module uses database driver to communicate with different database interfaces . because Qt Of SQL The interface of the model is database independent , So all the database specific code is included in these drivers .Qt The database driver supported now is shown in the figure below .
Two 、 Data manipulation language DML( Add or delete check change )
1. increase (INSERT)
● INSERT grammar
grammar 1:
INSERT INTO target [IN externaldatabase] (fields_list)
{
DEFAULT VALUES|VALUES(DEFAULT|expression_list)}
grammar 2:
INSERT INTO target [IN externaldatabase] fields_list
{
SELECT…|EXECUTE…}
● example
insert into teacher values(”,’allen’,' Dalian No.1 Middle School ’,'1976-10-10′);
insert into student values(1,' Zhang San ',21)
2. Delete (DELETE)
● DELETE grammar
DELETE FROM table_names
[WHERE…]
● example
① from students Delete the name in the table as “ Luo Liang ” The record of :
DELETE FROM students WHERE name = ' Luo Liang '
② from students In the table to delete ID by “3” The record of :
delete from students where id = 3
3. check (SELECT )
● complete SELECT grammar
SELECT [DISTINCT] [ Alias .] Field name or expression [AS Column headings ] /* Specify the columns or rows to select and their qualifications */
FROM table_source /* FROM Clause , Specify a table or view */
[ WHERE search_condition ] /* WHERE Clause , Specify query criteria */
[ GROUP BY group_by_expression ] /* GROUP BY Clause , Specify grouping expression */
[ ORDER BY order_expression [ ASC | DESC ]] /* ORDER BY Clause , Specify sort expression and order */
● example
① Inquire about Student database . Inquire about students Name and total credits of each student in the table .
USE Student SELECT name,totalscore FROM students
② Query all records in the table . Inquire about students All the information of each student in the table , Most used
SELECT * FROM students
③ Conditions of the query . Inquire about students The total credits in the table are greater than or equal to 120 The situation of my classmates .
SELECT * FROM students WHERE totalscore >= 120
④ Conditions of the query & Get the Department name and total score . Inquire about students The total credits in the table are greater than or equal to 120 The situation of my classmates .
SELECT department,name,totalscore FROM students WHERE totalscore >= 120
⑤ Multiple criteria query . Inquire about students The system in the table is “ Computer ” And the total credits are greater than or equal to 120 The situation of my classmates .
SELECT * FROM students WHERE department=' Computer ' AND totalscore >= 120
⑥ Use LIKE Predicate for pattern matching . Inquire about students Last name in the table “ king ” And the situation of single name students .
SELECT * FROM students WHERE name LIKE ' king _'
4. Change (UPDATE)
● UPDATE grammar
UPDATE table_name
SET Field_1=expression_1[,Field_2=expression_2…]
[FROM table1_name|view1_name[,table2_name|view2_name…]]
[WHERE…]
among ,Field Is the field that needs to be updated ,expression Represents the new value expression of the field to be updated .
● example
① Increase the total score of computer students 10:
UPDATE students
SET totalscore = totalscore + 10
WHERE department = ' Computer '
② take ID by 2 The name of the student is changed to “ Xiao Ming ”:
update students
SET name = ' Xiao Ming '
WHERE id = 2
QT For other articles, please click here : QT Learning notes
Reference resources : QT/C++ Foundation and improvement series QT Intermediate series of video courses
边栏推荐
- [QT] error: qapplication: no such file or directory solution
- 【Qt】error: QApplication: No such file or directory 解决方案
- ACM tutorial - heap sorting
- Leetcode 665 non decreasing array (greedy)
- [matlab] image transform (Fourier transform, discrete cosine transform)
- What if ROS lacks a package
- 小鱼儿的处理
- Basic underlying principles of concurrent programming (4)
- Initialize the one-dimensional array a correctly
- Win11触摸键盘主题如何更换?Win11更换触摸键盘主题的方法
猜你喜欢
![[leetcode] path sum II (first glimpse recursion + backtracking)](/img/a8/54920e54a026ebef3eb0a1336e5b62.jpg)
[leetcode] path sum II (first glimpse recursion + backtracking)

Px4 from abandonment to mastery (twenty four): customized model

How to change the theme of win11 touch keyboard? Win11 method of changing touch keyboard theme

In May, the main growth ranking list (platform of station B) of the single flying melon data up was released
![[cloud native | kubernetes] actual combat of ingress case](/img/99/1674f79e7ade0ec2f39e9b2c522d59.png)
[cloud native | kubernetes] actual combat of ingress case

Task01: be familiar with the basic process of news recommendation system

面试官:介绍一下你简历中的项目,细讲一点,附项目实战

flutter_ Swiper carousel map plug-in

(solved) latex -- cancel the superscript display of references in the text (gbt7714-2015 will lead to the default superscript reference) (tutorial on mixed use of superscript and flush)

MeterSphere教程:接口返回结果为空时如何进行断言
随机推荐
[music] playing "over fire" based on MATLAB [including Matlab source code 1875]
2021-3-1matlas MNIST database training for CNN writing
C语言 深度探究具有不定参数的函数
Programming implementation: input any English month, and output its corresponding Chinese prompt after looking up the month table. Abbreviations can also be found.
Leetcode 1567 maximum length of subarray with positive product
Treatment of small fish
On permutation and combination in probability and statistics
[leetcode] path sum II (first glimpse recursion + backtracking)
Method of using dism command to backup driver in win11 system
How to change the theme of win11 touch keyboard? Win11 method of changing touch keyboard theme
Sparrowrecsys recurrence record
---Arrange numbers---
视频压缩数据集TVD
Loki 学习总结(1)—— Loki 中小项目日志系统的不二之选
Leetcode 698 partition to K equal sum subsets (DFS pruning)
【MATLAB】图像变换(傅里叶变换、离散余弦变换)
Is it correct to declare an array in this way? int n=10,a[n]; What if so? const int n =10; int a[n];
LeetCode 1749 Maximum Absolute Sum of Any Subarray (dp)
Task06: bit operation
In May, the main growth ranking list (platform of station B) of the single flying melon data up was released