当前位置:网站首页>You need to use MySQL in the opening experiment. How can you forget the basic select statement? Remedy is coming~
You need to use MySQL in the opening experiment. How can you forget the basic select statement? Remedy is coming~
2022-07-03 09:44:00 【drhrht】
?? Catalog
??SQL The classification of sentences
SQL Language is divided according to function , It is mainly divided into the following 3 Categories: :
1、DDL(Data Definition Languages、 Data definition language )
, These statements define different databases 、 surface 、 View 、 Index and other database objects , It can also be used to create 、 Delete 、 Modify the structure of database and data table . The main statement keywords include CREATE 、DROP 、ALTER etc. .
2、DML(Data Manipulation Language、 Data operation language )
, Used to add 、 Delete 、 Update and query database records , And check data integrity . The main statement keywords include INSERT 、DELETE 、UPDATE 、SELECT etc. .SELECT yes SQL The basis of language , Above all .
3、DCL(Data Control Language、 Data control language )
, Used to define the database 、 surface 、 Field 、 User's access rights and security level . The main statement keywords include GRANT 、REVOKE 、COMMIT 、ROLLBACK 、SAVEPOINT etc.
understand :
Because query statements are used very frequently , Therefore, some people also bring out the query statement list , be called :DQL( Data query language ).
And alone will COMMIT 、ROLLBACK Take it out and call it TCL (Transaction Control Language, Transaction control language ).
??SQL Rules and norms of language
?? The basic rule
1、SQL It can be written on one or more lines . To improve readability , Write each clause separately , Use indent if necessary
2、 Every order is made with ; or g or G end
3、 Keywords cannot be abbreviated or separated
4、 About punctuation :
- All parentheses must be guaranteed ()、 Single quotation marks ’’、 Double quotes "" It ends in pairs
- Half angle input mode in English must be used
- Single quotation marks can be used for string and date time data (’ ') Express
- Alias of column , Try to use double quotes (" "), And it is not recommended to omit as
??SQL Case specification ( It is recommended that )
MySQL stay Windows The environment is case insensitive MySQL stay Linux The environment is case sensitive
It is precisely because of the two development environments , Case sensitivity is different , To prevent yourself from getting used to windows How to write in the environment , stay Linux It may be embarrassing when developing , So it is recommended to follow .
The following lists those that need to be strictly case sensitive :
Database name 、 Table name 、 The table alias 、 Variable names are strictly case sensitive
keyword 、 Function name 、 Name ( Or field name )、 Alias of column ( The alias of the field ) It's case insensitive .
With the development in depth , Engineers also imperceptibly formed some rules belonging to this circle : Database name 、 Table name 、 Table alias 、 Field name 、 Fields, aliases, etc. are all lowercase SQL Key words of 、 Function name 、 Bound variables, etc., are all capitalized
?? notes
The comments , It's something that happens in every development language , about SQL This is also the case , Because they facilitate our understanding of the code .
Single-line comments :# Note text (MySQL In a particular way )
Single-line comments :-- Note text (- - Must be followed by a space .)
Multiline comment :/* Note text */
?? Naming rules
SQL The naming rules of are similar to those of other programming languages , I believe most people are familiar with it .
1、 database 、 The table name must not exceed 30 Characters , Variable names are limited to 29 individual
2、 Must contain only A–Z, a–z, 0–9, _ common 63 Characters
3、 Database name 、 Table name 、 Do not include spaces in object names such as field names
4、 The same MySQL In software , The database cannot have the same name ; In the same library , A watch cannot have the same name ; In the same table , The field cannot have the same name
Here is an additional explanation of a special :
We must ensure that the fields we use , No and reserved words 、 Database systems or common methods conflict . If you insist on using , To be in SQL Use in statement `( mark of emphasis ) Lead up
# order yes sql A common command in order by Part of
SELECT * from `order`;
?? Data import instruction —— understand
?? Command line import and export
Command line sql File export :
1、 Specify a storage location sql
File folder
Such as : E:StudyMyDB
Export database file :mysqldump -u user name -p Database name -P Port number > Exported file name
For example, the code of the command line I entered is :mysqldump -u root -p test -P 3306>test.sql ( enter , Input MySQL Password )
If you want to export the specified table in the database : Just add the table name after the database name
mysqldump -u user name -p Database name Table name -P Port number > Exported file name
On the command line sql Import of files
Be careful : Import means , Is to take what I have now sql The file is imported into the database .
Here it is , You need to open up a space for this upcoming little guy in the database , Used to store the data of the database to be imported later .
therefore , The whole process is :
1、 Connect to database :mysql -u { user name } -p
enter Enter the password again
The implementation code is :
mysql -u root -p
2、 Specify the target database name :use { Library name }
The code is implemented as :
use newtest
3、 Import files source { route }
The code is implemented as :
source E:Studysql est.sql
It should be noted that we need to have this file , If there is no exception
?? Graphical management tools Navicat Premium Import and export of
If not Navicat Premium This software , But if you want to try, you can download it from the link below ~
Navicat Premium
One 、 Import operation
Step one : New database
The second step : Name the newly created database ( Recommendations and sql Same file name )
The third step : Click on " function SQL file "
Step four : Select the file to import
Two 、 Export operation
stay Navicat Premium Export in is very concise .
?? Basic SELECT sentence
??SELECT … FROM
The grammar is :SELECT
Specific query column name / Field name FROM
From which table to query
When you need to select all columns , Can use wildcard *
To achieve
The grammar is :SELECT *
FROM
From which table to query and select ;
Tips: :
?? Alias of column
Usage mode :
1、 Keep up with the column name , You can also add keywords between column names and aliases AS,
2、 When an alias contains spaces or special characters and is case sensitive , Aliases need to be enclosed in double quotes .
?? Remove duplicate information
By default , The query will return all rows , Include repeating lines . Because there's duplicate information , The whole result set will appear very cumbersome and bloated .
therefore :
stay SELECT Use keywords in statements DISTINCT Remove duplicate lines
The syntax is :SELECT DISTINCT
Name / Field name FROM
The table where the query field is located
?? Null values participate in the operation
All operators or column values encountered null value , The result of the operation is null
Be careful :
stay MySQL Inside , A null value is not equal to an empty string
. An empty string The length is 0
, And a null value The length is empty
. stay MySQL The empty value in the is the space occupied .
?? mark of emphasis
We need to ensure that the fields in the table 、 Table names, etc. have no and reserved words 、 Database systems or common methods conflict . If it's really the same , It needs to be in SQL A pair of... Is used in the statement ``( mark of emphasis ) Lead up .
?? Display table structure
Use DESCRIBE or DESC command , Represents the table structure
The syntax is :
DESCRIBE employees;
or
DESC employees;
?? Filtering data
Use the syntax :SELECT
Field 1, Field 2FROM
Table name WHERE
Filter conditions
Use WHERE Clause , Filter out rows that do not meet the criteria
WHERE Clause in the wake of FROM Clause
Sample demonstration
?? summary
This article mainly reviews SQL Some naming rules and specifications of statements , as well as SELECT
Statement and FROM
And WHERE
The data needed to combine to query . Take a brief look at the usage Syntax , Write one or two by yourself SQL Query cases , You can master .
that , Here are some small exercises , Interested partners can start to write it ~
Click to get the title and sql Papers ^ - ^
Click to get the reference code
边栏推荐
- PolyWorks script development learning notes (I) - script development environment
- [CSDN] C1 training problem analysis_ Part III_ JS Foundation
- 端午节快乐!—— canvas写的粽子~~~~~
- 【順利畢業】[1]-遊覽 [學生管理信息系統]
- Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 2 --blinker_ Hello_ WiFi (lighting technology - Mobile App control routine)
- Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
- LeetCode每日一题(1362. Closest Divisors)
- Install local sources using yum
- [CSDN]C1训练题解析_第三部分_JS基础
- PIP references domestic sources
猜你喜欢
CEF下载,编译工程
UCI and data multiplexing are transmitted on Pusch (Part 4) --small block lengths
[CSDN]C1訓練題解析_第三部分_JS基礎
numpy. Reshape() and resize() functions
Solve the problem of disordered code in vscode development, output Chinese and open source code
Nodemcu-esp8266 development board to build Arduino ide development environment
Matlab reads hexadecimal numbers and converts them into signed short
Hal library sets STM32 clock
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)
UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding
随机推荐
Hudi quick experience (including detailed operation steps and screenshots)
Jetson Nano 自定义启动图标kernel Logo cboot logo
Esp32 at command does not respond
Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
Please tell me how to set vscode
Global KYC service provider advance AI in vivo detection products have passed ISO international safety certification, and the product capability has reached a new level
Vscode Arduino installation Library
[graduation successful] [1] - tour [Student Management Information System]
[male nanny style] teach you to open the first wechat applet
Vector processor 9_ Basic multilevel interconnection network
[CSDN]C1训练题解析_第四部分_Web进阶
Chromium Embedded Framework (CEF) 介绍
Epollet lessons
[successful graduation] [1] - visit [student management information system]
Arduino handles JSON data, arduinojson assistant
专利查询网站
How does the nr-prach receiver detect the relationship between prembleid and Ta
Installation and uninstallation of pyenv
Directory and switching operation in file system
Leetcode daily question (1362. closest divisors)