当前位置:网站首页>MySQL advanced part 1: View
MySQL advanced part 1: View
2022-07-05 06:13:00 【Dawnlighttt】
List of articles
View overview
View (View) It's a virtual existence table . The view does not actually exist in the database , Row and column data comes from tables used in queries that define views , And it's dynamically generated when using views . Generally speaking , The view is just a line SELECT The result set returned after the statement is executed . So when we create views , The main job is to create this SQL On the query statement .
The advantages of a view over a regular table include the following .
- Simple : Users of views do not need to care about the structure of the corresponding tables 、 Association and screening criteria , It is already the result set of filtered composite conditions for users .
- Security : Users of views can only access the result set they are allowed to query , Permission management of a table cannot be limited to a row or a column , But it can be realized simply by view .
- Data independence : Once the structure of the view is determined , It can shield the influence of table structure change on users , Adding columns to the source table has no effect on the view ; Source table change column name , Can be solved by modifying the view , No impact on visitors .
Create or modify views
The syntax for creating a view is :
CREATE [OR REPLACE] [ALGORITHM = {
UNDEFINED | MERGE | TEMPTABLE}]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
ALTER [ALGORITHM = {
UNDEFINED | MERGE | TEMPTABLE}]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
Options :
WITH [CASCADED | LOCAL] CHECK OPTION Decide whether to allow the data to be updated so that the record no longer meets the view conditions .
LOCAL : You can update as long as you meet the conditions of this view .
CASCADED : All the conditions for all views for that view must be met to update . The default value is .
Example , establish city_country_view View , The implementation is as follows SQL :
create view city_country_view
as
select t.*,c.country_name from country c , city t where c.country_id = t.country_id;
Query view :

from MySQL 5.1 Version start , Use SHOW TABLES The command not only displays the name of the table , The name of the view is also displayed , There is no way to display views separately SHOW VIEWS command .

Again , In the use of SHOW TABLE STATUS When ordered , It can not only display the information of the table , At the same time, it can also display the information of the view .

If you need to query the definition of a view , have access to SHOW CREATE VIEW Command to view :

Delete view
grammar :
DROP VIEW [IF EXISTS] view_name [, view_name] ...[RESTRICT | CASCADE]
Example , Delete view city_country_view :
DROP VIEW city_country_view ;

边栏推荐
- Leetcode-1200: minimum absolute difference
- 对for(var i = 0;i < 5;i++) {setTimeout(() => console.log(i),1000)}的深入分析
- leetcode-6108:解密消息
- leetcode-6109:知道秘密的人数
- 开源存储这么香,为何我们还要坚持自研?
- Redis publish subscribe command line implementation
- leetcode-6110:网格图中递增路径的数目
- 1.15 - 输入输出系统
- SQLMAP使用教程(一)
- [rust notes] 15 string and text (Part 1)
猜你喜欢

可变电阻器概述——结构、工作和不同应用

1.15 - 输入输出系统

redis发布订阅命令行实现

Time of process

Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135

Traditional databases are gradually "difficult to adapt", and cloud native databases stand out

Groupbykey() and reducebykey() and combinebykey() in spark
![R language [import and export of dataset]](/img/5e/a15ab692a6f049f846024c98820fbb.png)
R language [import and export of dataset]

The connection and solution between the shortest Hamilton path and the traveling salesman problem

Dichotomy, discretization, etc
随机推荐
[rust notes] 17 concurrent (Part 1)
Currently clicked button and current mouse coordinates in QT judgment interface
1040 Longest Symmetric String
SQLMAP使用教程(一)
redis发布订阅命令行实现
Bit mask of bit operation
2022 极术通讯-Arm 虚拟硬件加速物联网软件开发
1.15 - input and output system
Individual game 12
SQLMAP使用教程(二)实战技巧一
Full Permutation Code (recursive writing)
1.14 - 流水线
[rust notes] 15 string and text (Part 1)
开源存储这么香,为何我们还要坚持自研?
2022年贵州省职业院校技能大赛中职组网络安全赛项规程
Data visualization chart summary (I)
可变电阻器概述——结构、工作和不同应用
Typical use cases for knapsacks, queues, and stacks
Leetcode-6108: decrypt messages
Daily question 1984 Minimum difference in student scores