当前位置:网站首页>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 ;
边栏推荐
- Attack and defense world web master advanced area PHP_ rce
- MySQL sub database and sub table and its smooth expansion scheme
- DCAT in laravel_ Admin preliminary use record
- [micro services ~nacos] Nacos service providers and service consumers
- PTA (daily question) 7-71 character trapezoid
- Simple use and understanding of laravel message queue
- Redis learning notes
- Locally connect to redis on Windows Server
- Html+css+php+mysql realize registration + login + change password (with complete code)
- Web系统常见安全漏洞介绍及解决方案-sql注入
猜你喜欢

ACM SIGIR 2022 | interpretation of selected papers of meituan technical team

Immutable x officially opens IMX token pledge detailed IMX pledge introduction optimistic about the development prospect of IMX

Dynamic programming problem (6)

Teach you how to install latex (nanny level tutorial)

PTA (daily question) 7-73 turning triangle

Event extraction and documentation (2018)

Attack and defense world web master advanced area web_ php_ unserialize

MySql中的like和in走不走索引

【esn】 学习回声状态网络

IDEA2021.2安装与配置(持续更新)
随机推荐
R语言怎么学
Dynamic programming (V)
Alibaba code index technology practice: provide reading experience of local IDE for code review
IMG tags prohibit dragging pictures
Application and principle of distributed current limiting redistribution rratelimiter
CV target detection model sketch (2)
PTA (daily question) 7-71 character trapezoid
刷题的第三十天
2022DASCTF7月赋能赛(复现)
Samsung asset management (Hong Kong) launched yuancosmos ETF to focus on investing in the future tuyere track
ACM SIGIR 2022 | interpretation of selected papers of meituan technical team
How to learn R language
Advanced area of attack and defense world web masters -baby Web
Statistical analysis of time series
vulnhub:Sar
Longest ascending subsequence
Kali installs burpsuite professional
动态规划问题(五)
[ESN] learning echo state network
PHP语言基础知识(超详细)