当前位置:网站首页>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
边栏推荐
- QT source code analysis -- QObject (2)
- [pytoch basic tutorial 31] youtubednn model analysis
- How does the tunnel mobile inspection track robot monitor 24 hours to ensure the safety of tunnel construction?
- What is SRE? A detailed explanation of SRE operation and maintenance system
- Summary of methods in numpy
- Using skills of xargs -- the way to build a dream
- Introduction to data platform
- 数据中台:国内大厂中台建设架构集锦
- ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis
- 什么是SRE?一文详解SRE运维体系
猜你喜欢

OpenCV每日函数 结构分析和形状描述符(7) 寻找多边形(轮廓)/旋转矩形交集

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

What is the future development trend of Business Intelligence BI

K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream

【牛客】HJ1 字符串最后一个单词的长度

What is SRE? A detailed explanation of SRE operation and maintenance system

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

pymysql 向MySQL 插入数据无故报错

【LeetCode】387. 字符串中的第一个唯一字符

【使用 PicGo+腾讯云对象存储COS 作为图床】
随机推荐
Ordering of MySQL composite index
ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis
Change SSH port number
数据中台:民生银行的数据中台实践方案
Array opposite pointer series
【E325: ATTENTION】vim编辑时报错
【NOI模拟赛】给国与时光鸡(构造)
开源之夏中选名单已公示,基础软件领域成为今年的热门申请
2021-05-20computed和watch应用与区别
基于单片机开发的酒精浓度测试仪方案
2020中国全国各省市,三级联动数据,数据机构(数据来自国家统计局官网)
K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream
JS to find and update the specified value in the object through the key
什么是SRE?一文详解SRE运维体系
微博撰写-流程图-序列图-甘特图-mermaid流程图-效果不错
IDEA另起一行快捷键
What is the future development trend of Business Intelligence BI
mysql写的代码数据 增删查改等等
[force deduction 10 days SQL introduction] Day3
数据中台:中台实践与总结