当前位置:网站首页>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
边栏推荐
- ACM教程 - 堆排序
- Project sorting of Online Exercise System Based on gin and Gorm
- [matlab] basic operation of MATLAB image processing
- 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];
- Task05: tree
- Well paid test development programmers, why are you leaving? Kill each other with products until the sky is dark
- [matlab] image restoration
- [leetcode] reverse linked list
- Leetcode 665 non decreasing array (greedy)
- [leetcode] ordered linked list transformation binary search tree
猜你喜欢

Dinner a bang's Craft
![[winning] Title A of the 9th Teddy Cup Challenge](/img/86/8445c4ac47d4fa7630544984fa0c58.jpg)
[winning] Title A of the 9th Teddy Cup Challenge

---Arrange numbers---
![[leetcode] restore binary search tree](/img/92/14c4d670f318f93297040241a61c41.jpg)
[leetcode] restore binary search tree

【BSP视频教程】BSP视频教程第17期:单片机bootloader专题,启动,跳转配置和调试下载的各种用法(2022-06-10)

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

【交通标志识别】基于matlab GUI YCbCr特征提取+BP神经网络交通标志识别【含Matlab源码 1869期】

5月B站榜单丨飞瓜数据UP主成长排行榜(B站平台)发布
![[traffic sign recognition] Based on Matlab GUI YCbCr feature extraction +bp neural network traffic sign recognition [including Matlab source code 1869]](/img/66/3f7134298e7e9a7fbf9b0c99dafb2a.jpg)
[traffic sign recognition] Based on Matlab GUI YCbCr feature extraction +bp neural network traffic sign recognition [including Matlab source code 1869]

Leetcode 652 find duplicate subtrees (recommended by DFS)
随机推荐
---Arrange numbers---
【MATLAB】图像增强(幂次变换、直方图规定化处理方法、平滑、锐化滤波)
[winning] Title A of the 9th Teddy Cup Challenge
MeterSphere教程:接口返回结果为空时如何进行断言
2021-02-27image processing of MATLAB
Win11怎么更改管理员头像?Win11更换管理员头像的方法
How to change the administrator's Avatar in win11? Win11 method of changing administrator image
Contest2902 - following Tang Kelian's programming: sequence structure question d: area 201502 question f: persistence of supporting college students in Ludian earthquake
[leetcode] a group of K flipped linked lists
[leetcode] construct a binary tree by traversing the sequence from front to middle (continuous optimization)
Database overview
[leetcode] flat multi-level bidirectional linked list
關於概率統計中的排列組合
【图像处理】基于matlab GUI多功能图像处理系统【含Matlab源码 1876期】
Question g: candy
EXJ形儿多眼前因断会满意接MBtXE
The argument type ‘int?‘ can‘t be assigned to the parameter type ‘num‘
【错误记录】Android 应用安全检测漏洞修复 ( StrandHogg 漏洞 | 设置 Activity 组件 android:taskAffinity=““ )
Matlab array other common operation notes
逻辑漏洞 / 业务漏洞