当前位置:网站首页>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


QT For other articles, please click here :     QT Learning notes

 Insert picture description here


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 :
 Insert picture description here
● QtSql Module hierarchy
 Insert picture description here
● 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 .
 Insert picture description here

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|VALUESDEFAULT|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

原网站

版权声明
本文为[Penguins on the volcano]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020622151536.html