当前位置:网站首页>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 ;
边栏推荐
- Locally connect to redis on Windows Server
- 时间序列统计分析
- Installation and use of pnpm
- "Method not allowed", 405 problem analysis and solution
- Application and principle of distributed current limiting redistribution rratelimiter
- html+css+php+mysql实现注册+登录+修改密码(附完整代码)
- 12个MySQL慢查询的原因分析
- Attack and defense world web master advanced area PHP_ rce
- PTA (daily question) 7-72 calculate the cumulative sum
- Alibaba Code代码索引技术实践:为Code Review提供本地IDE的阅读体验
猜你喜欢

MySQL的存储过程
![[micro services ~nacos] Nacos service providers and service consumers](/img/b7/47ecd6979ccfeb270261681d6130be.png)
[micro services ~nacos] Nacos service providers and service consumers

Html+css+php+mysql realize registration + login + change password (with complete code)

Introduction and solution of common security vulnerabilities in web system CSRF attack

Oracle实例无法启动的问题如何解决

Solutions such as failed plug-in installation and slow speed of linking remote server under vscode

Locally connect to redis on Windows Server

PTA (daily question) 7-74 yesterday

flyway的快速入门教程

Dynamic programming (V)
随机推荐
SAP VL02N 交货单过账函数 WS_DELIVERY_UPDATE
Event extraction and documentation (2008-2017)
@Detailed explanation of postconstruct annotation
ACM SIGIR 2022 | interpretation of selected papers of meituan technical team
Longest ascending subsequence
ORACLE not available如何解决
Teach you how to install latex (nanny level tutorial)
动态规划问题(二)
手把手教你安装Latex(保姆级教程)
PTA (daily question) 7-70 diamond
Advanced area of attack and defense world web masters -baby Web
Software designer - intermediate, exam summary
聊聊异步编程的 7 种实现方式
分布式限流 redission RRateLimiter 的使用及原理
Statistical analysis of time series
Why is it so difficult for the SEC to refuse the application for transferring gray-scale GBTC to spot ETF? What is the attraction of ETF transfer?
动态规划问题(七)
软考 --- 数据库(4)SQL语句
[ESN] learning echo state network
【MySQL 8】Generated Invisible Primary Keys(GIPK)