当前位置:网站首页>SQL statement
SQL statement
2022-07-01 06:27:00 【HHYZBC】
Catalog
SQL The classification of languages
Data processing functions ( Single line processing functions )
Group function ( Multiline processing functions )
Number of commonly used branch processing lines
SQL What is a statement
SQL Statements are also called structured query languages , Programmers write SQL sentence , How to execute the database otherwise SQL sentence , Finally, the operation of adding, deleting, modifying and querying data in the database is completed . Learning database is actually right SQL Sentence learning .
SQL The classification of languages
SQL There are many languages , Categorize commands , It's easier to remember ,
- DQL
- Represents a data query language ( Usually with select Keywords are all query statements )
- select...
- SQL in DQL sentence ( Inquire about )_HHYZBC The blog of -CSDN Blog
https://blog.csdn.net/HHYZBC/article/details/125190904
- DML
- Represents a data manipulation language ( All additions, deletions and modifications to the data in the table are DML)
- insert...
- increase
- deletr...
- Delete
- updata...
- Change
- SQL in DML sentence ( Data operation language )_HHYZBC The blog of -CSDN Blog _sql Of dml The core operation statements in
https://blog.csdn.net/HHYZBC/article/details/125191912
- DDL
- Representing data definition language ( Usually with creata、drop、alter The are DDL)
- DDL The operation is the structure of the table . Not the data in the table
- creata...
- newly build , Equivalent to increase
- drop...
- Delete
- alter...
- modify
- SQL in DDL sentence ( Data table definition language )_HHYZBC The blog of -CSDN Blog _sql Of ddl sentence
https://blog.csdn.net/HHYZBC/article/details/125191824
- TCL
- Represents a transaction control language
- commit
- Transaction submission
- rollback
- Transaction rollback
- sql in TCL sentence ( Transaction control statement )_HHYZBC The blog of -CSDN Blog
https://blog.csdn.net/HHYZBC/article/details/125385539?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22125385539%22%2C%22source%22%3A%22HHYZBC%22%7D&ctrtid=HI9qx
- DCL
- Represents data control language
- grant
- to grant authorization
- revoke
- Cancel the authorization
Data processing functions ( Single line processing functions )
Data processing functions are also called single line processing functions
Characteristics of single line processing functions : One input corresponds to one output .
The opposite of a single line handler is : Multiline processing functions .( Features of multiline processing functions : Multiple inputs , Corresponding 1 Outputs !), It will be written below .
- Common single line processing functions
- lower()
- Convert lowercase
- lower( The string being processed )
- upper()
- Convert a capital
- upper( The string being processed )
- substr()
- Intercept
- (substr( Intercepted string , Start subscript , Intercept length ))
- The starting subscript here is 1.
- concat()
- String concatenation
- concat( character string 1, character string 2)
- character string 2 You will receive a string 1 Behind
- length()
- Take the length
- length( data )
- trim()
- Go to space
- trim( The string being processed )
- str_to_date()
- Convert string to date
- str_to_date(' String date ', ' Date format ')
- mysql Date format for :
%Y year
%m month
%d Japan
%h when
%i branch
%s second - If the format of string date is %Y-%m-%d, You may not use this function ,MySQL It will be converted automatically
- date_format()
- Date format is converted to string type
- date_format( Date type data , ' Date format ')
- format()
- Set the thousandth
- format( Numbers , ' Format ')
- Format needs to be preceded by $ Number
- round()
- rounding
- round( value , Reserve the number of digits )
- The reserved digits can be negative numbers , If for -1 when , Will be kept to ten , And so on .
- rand()
- Generate random number
- The generated random numbers are all integers, and the part is 0 Decimals of .
- If you need to take 100 Random number within , You can generate random numbers *100.
- ifnull()
- Can be null Convert to a specific value
- ifnull( data , As what value )
- ifnull Is an empty handler . Specialized in dealing with empty . Of all the databases , As long as there is NULL Participating mathematical operations , The end result is NULL.
- now()
- Get the current time
- lower()
Group function ( Multiline processing functions )
The characteristics of multiline functions : Input multiple lines , The final output line .
Number of commonly used branch processing lines
- count()
- Count
- sum()
- Sum up
- avg()
- Average
- max()
- Maximum
- min()
- minimum value
- Be careful :
- The grouping function must be grouped before use , Then we can use . If you don't group the data , The whole table defaults to a group of .
- Grouping functions automatically ignore NULL, You don't need to tell me in advance NULL To deal with .
- In the grouping function count(*) and count( Specific fields ) What's the difference? ?
- count( Specific fields ): Indicates that all the statistics under this field are not NULL The total number of elements of .
- count(*): The total number of rows in the statistical table .( Just one line of data count be ++). Because every line of record cannot be NULL, One column in a row of data is not NULL
- Grouping functions cannot be used directly in where clause .
- Because the grouping function can only be used after grouping . And in the where What appears in , There is no grouping at this time .
Search engine
mysql Support nine storage engines , At present 5.5.36 Support 8 individual . Different versions support different situations .
have access to :show engines See which search engines , The only search engines you need to know are 3 Kind of :
MyISAM Storage engine
The tables it manages have the following characteristics :
Use three files to represent each table :
Format file — Definition of storage table structure (mytable.frm)
Data files — Store the contents of table rows (mytable.MYD)
Index file — Store indexes on tables (mytable.MYI): The index is the catalogue of a book , Narrow the scanning range , A mechanism to improve query efficiency .
Can be converted to compressed 、 Read only tables to save space
MyISAM Storage engine features :
Can be converted to compressed 、 Read only tables to save space
This is the advantage of this storage engine !!!!
MyISAM Transaction mechanism is not supported , Low security .
InnoDB Storage engine
This is a mysql The default storage engine , It is also a heavyweight storage engine .
InnoDB Support transactions , Support automatic recovery mechanism after database crash .
InnoDB The main feature of the storage engine is : Very safe .
The tables it manages have the following main characteristics :
– Every InnoDB The table is in the database directory as .frm The format file represents
– InnoDB Table space tablespace Used to store the contents of a table ( A tablespace is a logical name . Tablespaces store data + Indexes .)
– Provides a set of log files used to record transactional activities
– use COMMIT( Submit )、SAVEPOINT And ROLLBACK( Roll back ) Support transaction processing
– Provide full ACID compatible
– stay MySQL Provide automatic recovery after server crash
– Many versions (MVCC) And row level locking
– Support the integrity of foreign keys and references , Including cascading deletion and update
InnoDB The biggest feature is to support transactions :
To ensure data security . Not very efficient , And can't compress , Cannot convert to read-only ,
It can't save storage space well .
MEMORY Storage engine
Use MEMORY The table that stores the engine , Its data is stored in memory , And the length of the line is fixed ,
These two characteristics make MEMORY The storage engine is very fast .
MEMORY The tables managed by the storage engine have the following characteristics :
– In the database directory , Each table is marked with .frm Format file representation .
– Table data and indexes are stored in memory .( The goal is to , Quick query !)
– Table level locking mechanism .
– Can not contain TEXT or BLOB Field .
MEMORY The storage engine was formerly known as HEAP engine .
MEMORY Engine benefits : The query efficiency is the highest . No need to interact with the hard disk .
MEMORY Engine faults : unsafe , The data disappears after shutdown . Because the data and index are in memory .
about SQL The statement is , It's universal ,
be-all SQL Statement to “;” ending .mysql It's gone “;” Don't execute ,“;” End of the said !,
in addition SQL Statement is case insensitive , Will do .
Be careful : In all databases , Strings are uniformly enclosed in single quotes ,
Single quotation marks are standard , Double quotation marks in oracle Not in the database . But in mysql
Can be used in .
Again : All strings in the database are enclosed in single quotes . It's standard .
Double quotation marks are not standard .
In the database null You can't use the equal sign to measure . Need to use is null
Because in the database null Means nothing , It's not a value , So it can't be used
The equal sign measures .
Other commands
Log in to the database
- mysql -uroot -p
View currently used databases
- select database();
Just look at the structure of the table , There's an order :
- desc Table name ;
Display current time
- select now();
Exit database
- exit/quit/ctr+d
- Use any one
View all databases
- show databases;
Create database
- create database Database name charset= Coding format ;
- The encoding format is generally utf8 that will do
Using a database
- use Database name ;
Delete database
- drop database Database name ;
View all tables in the current database
- show tables;
View table structure
- desc Table name ;
View creation table SQL sentence
- show create table Table name ;
View creative Library SQL sentence
- show create database Database name ;
View constraints
select * from information_schema.TABLE_CONSTRAINTS where TABLE_NAME=" Table name ";
- Indicates the constraint name in the specified table ,where It can be omitted , Indicates to view all constraint names

- Red indicates the constraint name , Yellow indicates constraints
边栏推荐
- 交换机配置软件具有的作用
- Async and await
- 【KV260】利用XADC生成芯片温度曲线图
- 启牛学堂合作的证券公司是哪家?开户安全吗?
- [ManageEngine Zhuohao] use unified terminal management to help "Eurex group" digital transformation
- Free trial of self-developed software noisecreater1.1
- C语言课设工资管理系统(大作业)
- 端口扫描工具是什么?端口扫描工具有什么用
- 记磁盘扇区损坏导致的Mysql故障排查
- MongoDB:一、MongoDB是什么?MongoDB的优缺点
猜你喜欢

浅谈SIEM

Top 10 Free 3D modeling software for beginners in 2022

高阶-二叉搜索树详解
![阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]](/img/3c/7684b7c594f7871471f89007294703.png)
阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]

SQL语句

Teach you how to implement a deep learning framework

C language course set up salary management system (big homework)

How does the port scanning tool help enterprises?

【ManageEngine】如何实现网络自动化运维

C语言课设工资管理系统(大作业)
随机推荐
[leetcode] day91- duplicate elements exist
Picture server project test
[network security tool] what is the use of USB control software
Golang panic recover custom exception handling
SystemVerilog learning-10-validation quantification and coverage
[ITSM] what is ITSM and why does it department need ITSM
mysql约束学习笔记
H5网页判断是否安装了某个APP,安装则跳转未安装则下载的方案总结
ForkJoin和Stream流测试
What are the functions of LAN monitoring software
HCM Beginner (II) - information type
浅谈SIEM
C language course set up salary management system (big homework)
B-tree series
端口扫描工具对企业有什么帮助?
[ManageEngine] terminal management system helps Huasheng securities' digital transformation
【自动化运维】自动化运维平台有什么用
虚幻 简单的屏幕雨滴后处理效果
Camouflage request header Library: Anti useragent
Teach you how to implement a deep learning framework
https://blog.csdn.net/HHYZBC/article/details/125190904