当前位置:网站首页>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
边栏推荐
- Win11怎么更改管理员头像?Win11更换管理员头像的方法
- [QT] error: qapplication: no such file or directory solution
- LeetCode 1749 Maximum Absolute Sum of Any Subarray (dp)
- Metersphere tutorial: how to assert when the returned result of the interface is null
- [leetcode] breadth first search level traversal general disassembly template
- [leetcode] restore binary search tree
- ---排列数字---
- 基于Gin、Gorm实现的在线练习系统之项目梳理
- ACM tutorial - heap sorting
- 并发编程基础底层原理学习(四)
猜你喜欢

A brief history of neural network

Xpath注入

On permutation and Combination in Probabilistic Statistics

逻辑漏洞 / 业务漏洞

面试官:介绍一下你简历中的项目,细讲一点,附项目实战
![[leetcode] same tree + symmetric binary tree](/img/e5/40803ce66756c03737aa8991f7ec92.jpg)
[leetcode] same tree + symmetric binary tree
![[music] playing](/img/cf/63b04080867e93ab2e00e2e21b37df.jpg)
[music] playing "over fire" based on MATLAB [including Matlab source code 1875]

flutter_ Swiper carousel map plug-in

C语言 深度探究具有不定参数的函数
![[leetcode] ordered linked list transformation binary search tree](/img/9f/86e819beb8dc678d79c3e307891402.jpg)
[leetcode] ordered linked list transformation binary search tree
随机推荐
Programming implementation: input any English month, and output its corresponding Chinese prompt after looking up the month table. Abbreviations can also be found.
【MATLAB】图像变换(傅里叶变换、离散余弦变换)
Today's sleep quality record 80 points
Well paid test development programmers, why are you leaving? Kill each other with products until the sky is dark
flutter 状态管理
Win11画图工具没了怎么重新安装
Thoughts on small steamed stuffed bun's dividend
LeetCode 1749 Maximum Absolute Sum of Any Subarray (dp)
[winning] Title A of the 9th Teddy Cup Challenge
[traffic sign recognition] Based on Matlab GUI YCbCr feature extraction +bp neural network traffic sign recognition [including Matlab source code 1869]
[leetcode] construct a binary tree by traversing the sequence from front to middle (continuous optimization)
[leetcode] a group of K flipped linked lists
Win11怎么更改管理员头像?Win11更换管理员头像的方法
[matlab] basic operation of MATLAB image processing
Method of using dism command to backup driver in win11 system
Coordonnées des capitales provinciales des provinces chinoises
Initialize the one-dimensional array a correctly
[matlab] image segmentation
Sequence table exercises
Win11系统使用DISM命令备份驱动程序的方法