当前位置:网站首页>Basic syntax of MySQL DDL and DML and DQL
Basic syntax of MySQL DDL and DML and DQL
2022-07-24 04:27:00 【Stars slow】
Catalog
MySql Medium SQL Sentence classification
DDL Statement operation database
DDL Statement operation on Library
DDL Statement on the table in the Library
DML Basic syntax of statements
Data increase (INSERT sentence )
Data modification (UPDATE sentence )
Data deletion (DELETE sentence )
delete truncate drop difference
DQL Basic syntax of basic sentences ( Single table )
DQL Basic syntax of advanced statements ( Multiple tables )
Process control function statement ( Special inquiries )
MySql Medium SQL Sentence classification
SQL sentence , Structured query language (Structured Query Language), Is a special purpose programming language , It's one A database query and programming language , For data access and query 、 Update and manage relational database system , It's also a database Script file extension .

DDL Statement operation database
DDL Statement operation on Library
Create database

View all databases

• Be careful not to omit “s”
Delete database

Choose which database to use

DDL Statement on the table in the Library
View the tables in the library

Create table

for example :

View the data table structure created

Modify the name of the table

Modify the fields in the table

Delete the fields in the table

Add fields in the table

Delete table

DML Basic syntax of statements
Data increase (INSERT sentence )
keyword INSERT, The main function is to add records to the database table .
- grammar :

for example :
- Select a field to insert data

- Insert data in full fields
Be careful : When a full field is inserted , If the primary key increases automatically , To set the default , It can be used default / null
- Insert multiple pieces of data at once
Unusual new methods

Data modification (UPDATE sentence )
Keywords are UPDATE, The main function is to modify the existing records in the database table . It can be modified according to the conditions .
- grammar

for example :
Be careful : Modification must have where Clause condition , No addition where Condition refers to modifying all
Data deletion (DELETE sentence )
Keywords are DELETE, The main function room deletes the existing records in the database table . You can delete according to the conditions .
- grammar

for example :

Be careful : Delete must have where Clause condition , No addition where Condition refers to deleting all
- truncate Clear the table

delete truncate drop difference
- delete: Delete only the data in the table , Keep the index , Will not change the table structure
- truncate: Delete data from table + Indexes ( Reset index ), Will not change the table structure
- drop: Delete all in the table and delete the table structure ( The watch is gone )
DQL Basic syntax of basic sentences ( Single table )
Keywords are SELECT, The main function is to query the existing records in the database table .
- grammar
for example :

- Table alias and field alias

- Mode one : Add after field name as+ Alias
- Mode two : Add an alias after the field name and wrap it in quotation marks
- Mode three : Add an alias directly after the field name without quotation marks
- Remove duplication distinct

Get rid of SELECT Duplicate records in the returned record result of query ( All return columns have the same value ), Just return one
- WHERE Conditional clause

- WHERE Conditional clauses are not required ;
- WHERE Clause , You can add conditions to the query ;
- Conditions : Filter by , If not specified, modify all data of the table .
- LIKE keyword ( Fuzzy query )

- IN keyword ( Range queries )

- The value of the queried field , At least with IN One value in the parentheses after is the same ;
- Multiple values are separated by English commas .
- NULL Value query

- NULL representative “ No value ”;
- Different from zero 0 Null string ;
- Can only appear when the definition allows NULL Field of ;
- To be used IS NULL or IS NOT NULL Compare operators to compare .
DQL Basic syntax of advanced statements ( Multiple tables )
- Equivalent query ( Inline query ) And non equivalent query

- Similar to single table query , All are SELECT sentence ;
- Put multiple tables in FROM after , And separated by commas ;
- You can use AS Keywords are aliases , Easy to quote ;
- If there is no duplicate name query field, the designation of the data table can be omitted .
- Inline query (inner join)
grammar :SELECT * FROM surface 1INNER JOIN surface 2 ON Conditions
INNER JOIN: When at least one of the tables matches , Then return the record .
INNER JOIN give an example : 
- Outreach query (left join/right join)
grammar :SELECT * FROM surface 1 LEFT| RIGHTJOIN surface 2 ON strip
LEFT JOIN: From the left table ( surface 1) Return all records in , Even on the right ( surface 2) There are no matching lines in .
RIGHT JOIN: From the right table (table_2) Return all records in , Even if On the left (table_1) There are no matching lines in .
As shown in the following figure :

LEFT JOIN give an example :
RIGHT JOIN give an example :

- Find the union of two queries (UNION)
union Is to find the union of two queries .
union What is merged is the result set , Do not distinguish from which table , So you can merge the data queried from multiple tables .

Be careful :
- When the column names are inconsistent , The header of the first table will prevail , And its columns .
- union Duplicate rows will be filtered out .
- If the number of columns in the queried table is not equal , Will report a mistake .
- Sorting in each clause is meaningless ,mysql It will be ignored when merging .
- If the sort and in the clause limit It makes sense to combine .
- You can sort the consolidated whole table .
- union all Is to find the union of two queries , But it won't filter out the repetition , It's all displayed
Subquery
Subquery , It's also called internal query , All subqueries must be enclosed in parentheses
where Type subquery

from Type subquery
- Take the query results of the inner layer as a temporary table , For the outer layer sql Query again .
- The query result set can be treated as a table .
- The temporary table should use an alias .
exists Type subquery
- Put the outer layer sql Result , Get the inner layer sql To test , If the inner layer sql establish , Then the line takes out .
- The inner query is exists After the query .

Process control function statement ( Special inquiries )

- IF() function

- IFNULL() function

- Simple case

- Search for case

边栏推荐
- 工程师能力模型与技能要求
- 基于GL Pipeline与光线追踪技术的融合实现的台球模拟器
- J9 number theory: what is Web3.0? What are the characteristics of Web3.0?
- Chapter III query processing of PostgreSQL Guide - Insider exploration
- Ambire gas tank launches exclusive NFT launch
- .gz的业务交互和对外服篇中我们通合多个模型
- 高频小信号谐振放大器设计-课程设计Multisim仿真
- 64 attention mechanism 10 chapters
- Teacher qiniu said is the VIP account opened for you safe?
- C语言:冒泡排序法
猜你喜欢

Once svchost Troubleshooting of exe process occupying a large amount of network bandwidth

MySQL service 1 master 2 slave, master master, MHA configuration detailed steps

基于C语言设计的一个医院叫号系统

直播课堂系统04-创建service模块

高频小信号谐振放大器设计-课程设计Multisim仿真

微波技术基础实验二 功分器与定向耦合器设计
【望解答】数据无法正确同步了

C语言经典习题之评委打分去掉最高最低求平均分
![[translation] announce krius -- accelerate your monitoring and adoption of kubernetes](/img/6c/be19a910e60da701a054c4bf689000.jpg)
[translation] announce krius -- accelerate your monitoring and adoption of kubernetes

Hardware knowledge 3 -- IIC protocol
随机推荐
一次 svchost.exe 进程占用大量网络带宽的排查
Insider of LAN SDN hard core technology 22 Kang long regrets -- Specifications and restrictions (Part 2)
Avoid mistakes, common appium related problems and Solutions
Game improvement of smart people: Lesson 2 of Chapter 3: number of factors
Can NFT pledge in addition to trading?
Game improvement of smart people: Chapter 3 Lesson 3: find game
LAN SDN hard core technology insider 21 Kang long regrets -- Specifications and restrictions (middle)
How about opening an account for Guotai Junan Securities? Is it safe
What if the references in the word sent by others are {} in such a garbled format
Engineer competency model and skill requirements
Pyth去初始化平均在很多机器学决策边界,始向总线上
【C语言】程序环境和预处理操作
What is the general family of programmers working in first tier cities?
An accident caused by MySQL misoperation, and "high availability" can't withstand it
Smart people's game improvement: Chapter 3 Lesson 3 example: the secret of prime
Particle Designer:粒子效果制作器,生成plist文件并在工程中正常使用
postgresql源码学习(32)—— 检查点④-核心函数CreateCheckPoint
Send data 1010_ 1. The number of bytes passed by the sender
Redis sentinel mode, master node check script
LAN SDN technology hard core insider 9 from software overlay to hardware overlay