当前位置:网站首页>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;
边栏推荐
- Ubuntu20.04 PostgreSQL 14 installation configuration record
- There are spaces in the for loop variable in the shell -- IFS variable
- Raspberry pie 4B learning notes - IO communication (1-wire)
- error: . repo/manifests/: contains uncommitted changes
- Exclusive delivery of secret script move disassembly (the first time)
- Six lessons to be learned for the successful implementation of edge coding
- "C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure
- 技术大佬准备就绪,话题C位由你决定
- [Floyd] post disaster reconstruction
- uTools
猜你喜欢

This is the form of the K-line diagram (pithy formula)

How to debug apps remotely and online?

Study note 2 -- definition and value of high-precision map

Exclusive delivery of secret script move disassembly (the first time)

The role of artificial intelligence in network security

卷积神经网络(包含代码与相应图解)

如何远程、在线调试app?

现货黄金分析的技巧有什么呢?
![[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production](/img/b7/aecb815ca9545981563a1e16cfa19e.jpg)
[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production

What is AQS and its principle
随机推荐
Ks006 student achievement management system based on SSM
Bat Android Engineer interview process analysis + restore the most authentic and complete first-line company interview questions
Learning note 3 -- Key Technologies of high-precision map (Part 1)
Automatically browse pinduoduo products
Matlab uses resample to complete resampling
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure
The technology boss is ready, and the topic of position C is up to you
Finally got byte offer, 25-year-old inexperienced experience in software testing, to share with you
ES6 new method of string
基于SSM实现微博系统
Fastadmin controls the length of fields in the table
10 minutes to get started quickly composition API (setup syntax sugar writing method)
电商系统中常见的9大坑,你踩过没?
浅浅了解Servlet
卷積神經網絡(包含代碼與相應圖解)
电子协会 C语言 1级 33 、奇偶数判断
Learn basic K-line diagram knowledge in three minutes
MPLS experiment operation
Pyldavis installation and use | attributeerror: module 'pyldavis' has no attribute' gensim '| visual results are exported as separate web pages
How to debug apps remotely and online?