当前位置:网站首页>MySQL | view notes on Master Kong MySQL from introduction to advanced
MySQL | view notes on Master Kong MySQL from introduction to advanced
2022-06-24 08:52:00 【Begonia_ cat】
List of articles
1. View concept
Create a view from a table , Then this table is called
Base watch.A view is a
Virtual table, amount toSELECTEncapsulation of statements .Cover upSheepskinSELECT OfThe WolfViewCreate viewperhapsDelete viewIn itself , Does not affect the base table .
2. Why use views ?—— Query query !
For convenience Inquire about . Repeat three times , remember , Only for query !
When you just want to show specific content to specific people , Using views can simplify queries .
Image memory : The view is like a magic mirror , It only shows a part of the base table that allows you to see .
(1) advantage
Compared with the new word table , It can reduce the redundancy of data .
Views are isolated , Protect raw data , Help data security .
When the query is complex , You can create multiple views , Then integrate the results of these views , Complete complex queries .
therefore , For view , Don't get rid of those fancy things , Such as adding, deleting and modifying !
The view is a virtual window , So do itDML( Additions and deletions ) In operation , Directly to Base watch ConductDMLoperation .
- insert data
INSERT( When the fields in the base table have constraints , Insert data if it does not conform to the constraint , The insertion fails )- Update data
UPDATE- Delete data
DELETE
Fields in view , There may be no corresponding field in the base table . such as ,Fields calculated from the base table. For these fields , It's impossible to executeUPDATE、DELETEOperation of the .
Just look at this passage , It is not recommended to use !
(2) shortcoming
Maintenance costs are high
3. Create view
CREATE OR REPLACE VIEW ViewCan be used directlyCreate or modify views. In fact, it is basically written like this .
.
Because it is not mentioned hereModify the view, So first, simply useCREATE VIEWTo introduce .
(1) Single table
CREATE VIEW View name ( Field alias 1, Field alias 2, ...) -- If it has the same name as the field in the query , Alias names can be omitted `( Field alias 1, Field alias 2, ...)`
AS
SELECT Field 1, Field 2, ...
FROM Table name
WHERE Filter conditions
(2) Multiple tables
CREATE VIEW View name ( Field alias 1, Field alias 2, ...) -- If it has the same name as the field in the query , Alias names can be omitted `( Field alias 1, Field alias 2, ...)`
AS
SELECT Table name . Field 1, Table name . Field 2, ...
FROM Table name 1, Table name 2
ON Table name 1. Field = Table name 2. Field ;
WHERE Filter conditions
(3) Create a view based on the view
hold View regard as surface Just write the code , There is no difference in the code .
4. View view
(1) Show the view
SHOW TABLES;
(2) Look at the structure of the view
DESC View name
(3) See the details of the view
SHOW CREATE VIEW View name
(4) Query all contents in the view
SELECT *
FROM View name
5. Modify the view
Common topics : take ... Restriction on ... Within the scope of
(1) Add one more OR REPLACE Just go
You can use this code directly Create or modify views .
CREATE OR REPLACE VIEW View name
AS
Query statements for base tables
(2)ALTER VIEW
ALTER TABLE View name
AS
Query statements for base tables
6. Delete view
DROP VIEW IF EXISTS View name
边栏推荐
- Matlab camera calibrator camera calibration
- orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘
- Picture tools
- Centos7 installation of jdk8, mysql5.7 and Navicat connection to virtual machine MySQL and solutions (solutions to MySQL download errors are attached)
- 520. 检测大写字母
- Jenkins is deployed automatically and cannot connect to the dependent service [solved]
- MySQL | 视图《康师傅MySQL从入门到高级》笔记
- China chip Unicorn Corporation
- Using ngrok for intranet penetration
- A tip to read on Medium for free
猜你喜欢

KaFormer个人笔记整理

【NOI模拟赛】寄(树形DP)

数云发布2022美妆行业全域消费者数字化经营白皮书:全域增长破解营销难题

MySQL | 视图《康师傅MySQL从入门到高级》笔记

教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5

Prompt code when MySQL inserts Chinese data due to character set problems: 1366

WebRTC系列-网络传输之5选择最优connection切换

The form image uploaded in chorme cannot view the binary image information of the request body

Become an IEEE student member

Matlab camera calibrator camera calibration
随机推荐
GradScaler MaxClipGradScaler
Matlab camera calibrator camera calibration
常用表情符号
Liunx change the port number of vsftpd
2021-05-20computed和watch应用与区别
不能改变虚拟机电源状态报错解决方案
RuntimeError: Missing dependencies:XXX
[force deduction 10 days SQL introduction] Day3
【LeetCode】415. 字符串相加
“不平凡的代理初始值设定不受支持”,出现的原因及解决方法
Pymysql inserts data into MySQL and reports an error for no reason
【NOI模拟赛】摆(线性代数,杜教筛)
项目部署相关
基于单片机开发的酒精浓度测试仪方案
2022 spring recruitment interview summary
【牛客】HJ1 字符串最后一个单词的长度
Prompt code when MySQL inserts Chinese data due to character set problems: 1366
Why do you want to file? What are the advantages and disadvantages of website filing?
K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream
Determination of monocular and binocular 3D coordinates