当前位置:网站首页>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;
边栏推荐
- New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
- Exclusive delivery of secret script move disassembly (the first time)
- ES6 new method of string
- SQLite 3 of embedded database
- Based on configured schedule, the given trigger will never fire
- 5g/4g pole gateway_ Smart pole gateway
- Parted command
- Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months
- How can I batch produce the same title for the video?
- 电商系统中常见的9大坑,你踩过没?
猜你喜欢

机器学习基本概念

人工智能在网络安全中的作用

With the innovation and upgrading of development tools, Kunpeng promotes the "bamboo forest" growth of the computing industry

Android high frequency network interview topic must know and be able to compare Android development environment

Raspberry pie 4B learning notes - IO communication (1-wire)

The smart Park "ZhongGuanCun No.1" subverts your understanding of the park
![[rust web rokcet Series 2] connect the database and add, delete, modify and check curd](/img/23/cfa13ad30e45ef7cdda690775964a7.jpg)
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd

Discussion on the idea of platform construction

matlab 使用 resample 完成重采样
![[IVX junior engineer training course 10 papers to get certificates] 0708 news page production](/img/ad/a1cb672d2913b6befd6d8779c993ec.jpg)
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production
随机推荐
Based on configured schedule, the given trigger will never fire
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
[Floyd] post disaster reconstruction
matlab 使用 audioread 、 sound 读取和播放 wav 文件
如何用一款产品推动「品牌的惊险一跃」?
[IVX junior engineer training course 10 papers to get certificates] 09 chat room production
Edge computing accelerates live video scenes: clearer, smoother, and more real-time
Basic concepts of machine learning
6-2漏洞利用-ftp不可避免的问题
No converter found for return value of type: class
MPLS experiment operation
Is the knowledge of University useless and outdated?
Based on configured schedule, the given trigger will never fire
Private project practice sharing [Yugong series] February 2022 U3D full stack class 009 unity object creation
Number of palindromes in C language (leetcode)
Leetcode, 3 repeatless longest subsequence
Fastadmin controls the length of fields in the table
Tencent cloud techo youth dream campus trip into Wuhan University
Quatre stratégies de base pour migrer la charge de travail de l'informatique en nuage
Failed to transform file 'xxx' to match attributes