当前位置:网站首页>MySQL view concept, create view, view, modify view, delete view
MySQL view concept, create view, view, modify view, delete view
2022-07-02 01:46:00 【No development, no work】
List of articles
1 Concept of view
- View is a virtual table , There is no data in itself , Takes up very little memory space , It is SQL An important concept in .
- Views are built on existing tables , The tables on which the view is built are called Base watch .

- The creation and deletion of views only affect the view itself , It does not affect the corresponding base table . But when the data in the view is added 、 When deleting and modifying operations , The data in the data table will change accordingly , vice versa .
- The statement that provides data content to the view is SELECT sentence , A view can be understood as Stored up SELECT sentence .
- In the database , The view does not save data , The data is really saved in the data table . When adding data to the view 、 When deleting and modifying operations , The data in the data table will change accordingly ; vice versa .
- View , Is another form of providing users with base table data . Usually , Databases for small projects may not use views , But on big projects , And when the data table is complex , The value of view is highlighted , It can help us put the result set of frequent queries into the virtual table , Improve efficiency . It is very convenient to understand and use .
2 Create view
2.1 grammar
- stay CREATE VIEW Insert subquery in statement
CREATE [OR REPLACE]
[ALGORITHM = {
UNDEFINED | MERGE | TEMPTABLE}]
VIEW View name [{ Field list }]
AS Query statement
[WITH [CASCADED|LOCAL] CHECK OPTION]
- Lite version
CREATE VIEW View name [( Field list )]
AS Query statement
2.2 Name the field
-- Mode one
CREATE VIEW emp_view AS SELECT
employee_id emp_id,-- The column name of the view is consistent with the alias
last_name lname,
salary
FROM
employees;
-- Mode two
-- The name should correspond to the query field one by one
CREATE VIEW emp_view2 ( emp_id, lname, money ) AS SELECT
employee_id,
last_name,
salary
FROM
employees;
3 View view
-- View tables and views
SHOW TABLES;
-- View view structure
DESC emp_view2;
-- View the attribute information of the view
SHOW TABLE STATUS LIKE 'emp_view2';
-- View the detailed definition information of the view
SHOW CREATE VIEW emp_view2;
4 Modify the view
-- Create a view to modify
CREATE VIEW emp_view AS SELECT
employee_id emp_id,
last_name lname,
salary
FROM
employees;
-- Modification method 1
CREATE OR REPLACE VIEW emp_view AS SELECT
employee_id,
last_name,
salary,
email
FROM
employees
WHERE
salary > 7000;
-- Modification method 2
ALTER VIEW emp_view AS SELECT
employee_id emp_id,
last_name lname,
salary
FROM
employees;
5 Delete view
-- Delete view
DROP VIEW IF EXISTS emp_view;
DROP VIEW IF EXISTS emp_view,emp_view2;
边栏推荐
- Game thinking 15: thinking about the whole region and sub region Services
- [Floyd] post disaster reconstruction
- I Brief introduction of radio energy transmission technology
- C language 3-7 daffodils (enhanced version)
- Private project practice sharing [Yugong series] February 2022 U3D full stack class 009 unity object creation
- np.where 和 torch.where 用法
- The author is more willing to regard industrial Internet as a concept much richer than consumer Internet
- Should enterprises choose server free computing?
- It's already 30. Can you learn programming from scratch?
- Implementation of Weibo system based on SSM
猜你喜欢

分卷压缩,解压

浅浅了解Servlet

【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享
![[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface](/img/c9/3fe8693629a8452dcfdb4349ddee0d.png)
[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface

New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port

What are the skills of spot gold analysis?

Self drawing of menu items and CListBox items

Learning note 3 -- Key Technologies of high-precision map (Part 1)

Raspberry pie 4B learning notes - IO communication (1-wire)
![[rust web rokcet Series 1] Hello, world and get, post, put, delete](/img/d8/7dd5fe409d349a13128b6af554f952.jpg)
[rust web rokcet Series 1] Hello, world and get, post, put, delete
随机推荐
Based on configured schedule, the given trigger will never fire
Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
Finally got byte offer, 25-year-old inexperienced experience in software testing, to share with you
Makefile simple induction
并发编程的三大核心问题
The difference between new and malloc
[Floyd] post disaster reconstruction
It's already 30. Can you learn programming from scratch?
How can I batch produce the same title for the video?
Learn C language from scratch day 025 (maze)
matlab 使用 audioread 、 sound 读取和播放 wav 文件
The technology boss is ready, and the topic of position C is up to you
error: . repo/manifests/: contains uncommitted changes
What are the skills of spot gold analysis?
Convolutional neural network (including code and corresponding diagram)
How to use a product to promote "brand thrill"?
Modeling essays series 124 a simple coding method
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
企业应该选择无服务器计算吗?
Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months