当前位置:网站首页>SQL Basics
SQL Basics
2022-07-26 23:06:00 【Planning Department_ xiao_ cai_ ji】
Information
according to 【MySQL Database tutorial ,mysql The installation to mysql senior , strong ! hard !】 Arrangement
The data link :
Baidu SkyDrive :
link :https://pan.baidu.com/s/1KboU_3EZJxrezMWZ2klP6g
Extraction code :1234
Alicloud disk
【MySQL】
1. SQL The classification of
- SQL The function of language is mainly divided into the following 4 Categories: :
- (1) DDL(Data Definition Languages – Data definition language ):
- DDL It can be used to 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 .
- DDL The main statement keywords include ( First understand the meaning of keywords ):
- CREATE: establish
- ALTER: modify
- DROP: Delete
- RENAME: rename
- TRUNCATE: Delete the data and create a new one as before ( Empty )
- (2) DML(Data Manipulation Language – Data operation language ):
- Used to add 、 Delete 、 Update database records , And check data integrity .
- DML The main statement keywords include ( First understand the meaning of keywords ):
- INSERT: insert data
- DELETE: Delete data
- UPDATE: modify / Update data
- (3) DQL(Data Query Language – Data query language ):
- Used to query database records .
- DQL The main statement keywords include ( First understand the meaning of keywords ):
- SELECT( A top priority ): Query data
- (4) DCL(Data Control Language – Data control language ):
- Used to define the database 、 surface 、 Field 、 User's access rights and security level .
- DCL The main statement keywords include ( First understand the meaning of keywords ):
- COMMIT: Commit transaction
- ROLLBACK: Roll back the transaction
- SAVEPOINT: Rollback to a specific savepoint
- GRANT: To give permission
- REVOKE: Revoke authority
- (5) Add :
- Some people will COMMIT 、 ROLLBACK Take it out and call it TCL (Transaction Control Language, Transaction control language ).
First, add some explanations SQL sentence :
(1) Specify which database to use :USE Database name ;
(2) View currently used databases :SELECT DATABASE();
(3) View all databases :SHOW DATABASES;
(4) View all tables in the current database :SHOW TABLES;
2.SQL The rules and norms of
2.1 SQL The rules of ( Must abide by )
SQL It can be written on one or more lines . To improve readability , Write each clause separately , Use indent if necessary ( Sometimes a sentence SQL The statement may be very long ).
for example :
DELETE FROM edge WHERE (edge_first = 2 AND edge_second = 3) OR (edge_first = 3 AND edge_second = 2); # It's written in DELETE FROM edge WHERE (edge_first = 2 AND edge_second = 3) OR (edge_first = 3 AND edge_second = 2);Every order is made with
;or\gor\Gend
It can be seen from the screenshot that
;End and end with\gThe execution results at the end are consistent , With\GExecution result at the end , Only the data is displayed in different ways , From the original use of tables for display to the use of dictionaries (Column names in the table : result) Display in the format of .Keywords cannot be abbreviated or separated
SHOW DATA BASES;[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATA BASES' at line 1About punctuation
① All must be guaranteed ()、 Single quotation marks 、 Double quotes end 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
2.2 SQL The specification of ( It is recommended that )
MySQL stay Windows The environment is case insensitive
stay windows Create two new folders , The names of the two folders are the same , Only the case of letters is different ,window You will think that the names of two folders are the same , So in windows Case insensitive under the system , As a result windows Under the SQL Case insensitive .

MySQL stay Linux The environment is 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 .A unified writing standard is recommended ( Prevent being affected under different systems ):
① Database name 、 Table name 、 Table alias 、 Field name 、 Fields, aliases, etc. are all lowercase
② SQL keyword 、 Function name 、 Bound variables, etc., are all capitalized
2.3 Naming rules ( understand )
- database 、 The table name must not exceed 30 Characters , Variable names are limited to 29 individual
- Must contain only A–Z, a–z, 0–9, _ common 63 Characters
- Database name 、 Table name 、 Do not include spaces in object names such as field names
- 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
- You must ensure that your field has no and reserved words 、 Database systems or common methods conflict . If you insist on using , Please be there. SQL Use in statement `( mark of emphasis ,1 To the right of , Top left of keyboard ) Lead up
- Keep field names and types consistent , When naming fields and specifying data types for them, be sure to ensure consistency . If the data type is an integer in a table , Then don't turn into character in another table
3.MySQL Notes
Single-line comments :
grammar :
# What needs to be annotated # The annotation method is MySQL Uniqueperhaps
-- What needs to be annotated -- Use this method to annotate ,-- There must be a space after , Otherwise, the line is not considered to be annotated
Multiline comment :
grammar :/* What needs to be annotated What needs to be annotated What needs to be annotated */Cannot nest in multiline comments

边栏推荐
- 【HCIP】OSPF 路由计算
- 总投资100亿美元,华虹无锡12吋晶圆厂正式投产
- 数据库全栈工程师(DevDBOps)低首付、高回报,先就业后付款
- 提前批到底影不影响正式批?
- 面试:你印象最深的BUG,举个例子
- 研究阿尔茨海默病最经典的Nature论文涉嫌造假
- 沟通中经常用到的几个库存术语
- 7.27 watch first | openeuler is ambitious, open source Huizhi creates the future - the most detailed agenda of the Euler sub forum of the open atom global open source summit is released
- 基于信心上界蒙特卡洛搜索树(UCT)实现四子棋
- SQL multi table query exercise
猜你喜欢

Counter attack dark horse: devdbops training, give you the best courses!

Esmfold: a new breakthrough in protein structure prediction after alphafold2

利用Go制作微信机器人(一)发送消息

Page file system based on C language

The JSON string is converted into a JSON object, the value of a key is obtained, and whether a key exists is judged

科研太忙无法顾家?陈婷:人生不能只有一个支点

【flask高级】结合源码分析flask中的线程隔离机制

Do you know the common core types of magnetic ring inductors?

Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China

Detailed explanation of SQL secondary injection
随机推荐
Calendar documents implemented by several qwidgets
PostgreSQL 与 Navicat:数据库行业的中坚力量
Hcia-r & s self use notes (20) VLAN comprehensive experiment, GVRP
ESMFold: AlphaFold2之后蛋白质结构预测的新突破
Interview: your most impressive bug, for example
Openstack virtual machine network card is renamed cirename0
【MySQL】CentOS 7.9安装、使用MySQL-5.7.39二进制版
2019 biometric forum successfully ended: these ten highlights should not be missed!
With a total investment of 10billion US dollars, Huahong Wuxi 12 inch wafer factory was officially put into operation
【flask高级】结合源码分析flask中的线程隔离机制
Sequence table implementation
基于gRPC编写golang简单C2远控
A13 processor has become the biggest highlight of iphone11 series: its performance is twice that of Kirin 980!
DAO:OP 代币和不可转让的 NFT 致力于建立新的数字民主
Page file system based on C language
菜鸟网络面试【杭州多测师】【杭州多测师_王sir】
[paper reading] logan:membership influence attacks against generative models
2022 latest Tibet Construction Safety Officer simulation question bank and answers
科研太忙无法顾家?陈婷:人生不能只有一个支点
The interviewer asked: this point of JS