当前位置:网站首页>Soft test --- database (4) SQL statement
Soft test --- database (4) SQL statement
2022-07-29 00:33:00 【Caterpillars who want to write programs】
SQL Language
1.1 Definition
SQL Structured query language ( Structured Query Language ) Abbreviation , Its functions include data query 、 Data manipulation 、 Data definition and data control are four parts ;
- SQL The language is simple 、 Convenient and practical 、 The function is all ready , It has become the most widely used relational database language ;
- SQL It's self-contained language ( Online interaction ), Embedded language again ( Host language );
1.2 Two basic concepts
Basic table :
Is an independent table , Tables that are not exported from other tables , A relationship corresponds to a basic table , One or more basic tables correspond to one storage file ;
View :
A view is a virtual table , It is a table exported from one or several basic tables , The database only stores the definition of the view, not the data corresponding to the view , This data is still stored in the base table of the exported view , When the data in the basic table changes , The data queried from the view also changes ;
1.3 Data definition
SQL Language uses data definition language ( DDL ) Realize its data definition function , For database users 、 Basic table 、 View 、 Index to define and undo ;
1.3.1 Define the base table
CREATE TABLE < Table name >( < Name > < data type > < Column level integrity constraints > )
< Table name > Legal identifier , most 128 Characters , Such as S , SC , C , Duplicate names are not allowed ;
1.3.2 Modify the basic table
ALTER TABLE < Table name >
[ ADD < New column names > < data type > [ Integrity constraints ] ]
[ ALTER COLUMN < Name > < data type > ]
[ DROP < COLUMN Name > | < Integrity constraint name > ]
- ADD Clause : Add new columns and new integrity constraints ;
- ALTER COLUMN Clause : Used to modify Columns ;
- DROP Clause : Delete the specified column or integrity constraint ;
1.3.3 Delete table
DROP TABLE < Table name >
After deleting the basic table , The data and the index built on the table are deleted , The view established on this table will not be deleted , The system will continue to retain its definition , But it can no longer be used ;
1.3.4 Define views
CREATE VIEW < View name > [ ( < Name > [ < Name > ] …… ) ]
AS
< Subquery >
[ with check option ]
1.3.5 Delete view
DROP VIEW < View name >
1.4 Query statement
1.4.1 SELECT General format of statement
SELECT [ ALL | DISTINCT ] < Target list expression > [ , < Target list expression > ]
FROM < Table or view name > [ , < Table or view name > ] …… | ( SELECT sentence )
[ AS ]< Alias >
[ WHERE < Conditional expression > ]
[ GROUP BY < Name 1 > [ HAVING < Conditional expression > ] ]
[ ORDER BY < Name 2 > [ ASC | DESC ]];
1.4.2 SELECT Implementation process of
- according to WHERE Search condition of clause , from FROM Select the tuples that meet the conditions in the basic table or view specified by clause , Again according to SELECT Clause to get the result table ;
- If there is GROUP Clause . Then the query results will be according to < Name 1 > Group the same values ;
- If DROUP Clause followed by HAVING The phrase , Then only the output meets HAVING Conditional tuple ;
- If there is ORDER Clause , The query results should also be in accordance with < Name 2 > Arrange values of ;
1.4.3 Link query
There are two ways to connect tables :
- Rows between tables that meet certain conditions are connected , here FROM Clause indicates the name of the table to connect , WHERE Clause indicates the column name of the connection and its connection condition ;
- Using keywords JOIN Connect ;
边栏推荐
猜你喜欢
【飞控开发基础教程8】疯壳·开源编队无人机-I2C(激光测距)
PTA (daily question) 7-70 diamond
IDEA2021.2安装与配置(持续更新)
flyway的快速入门教程
乱打日志的男孩运气怎么样我不知道,加班肯定很多!
聊聊异步编程的 7 种实现方式
Dynamic programming (V)
Advanced area of attack and defense world web masters supersqli
Advanced area of attack and defense world web masters warmup
Attack and defense world web master advanced area PHP_ rce
随机推荐
CV target detection model sketch (2)
Recursion / backtracking (middle)
SAP VL02N 交货单过账函数 WS_DELIVERY_UPDATE
What does WGet mean
What are the skills of API interface optimization?
Dynamic programming problem (2)
MySQL 分库分表及其平滑扩容方案
Event extraction and documentation (2018)
Idea connection database
IMG tags prohibit dragging pictures
Advanced area of attack and defense world web masters -baby Web
12个MySQL慢查询的原因分析
Attack and defense world web master advanced area php2
1331. Array sequence number conversion: simple simulation question
动态规划问题(六)
Software designer afternoon question
Locally connect to redis on Windows Server
Anti shake and throttling
[applet project development -- JD mall] uni app commodity classification page (first)
软考 --- 数据库(4)SQL语句