当前位置:网站首页>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 ;
边栏推荐
- 【Rust 笔记】15-字符串与文本(上)
- QQ computer version cancels escape character input expression
- Typical use cases for knapsacks, queues, and stacks
- Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
- How to adjust bugs in general projects ----- take you through the whole process by hand
- The connection and solution between the shortest Hamilton path and the traveling salesman problem
- 927. Trisection simulation
- Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
- Transform optimization problems into decision-making problems
- 1.13 - RISC/CISC
猜你喜欢
LeetCode 0107. Sequence traversal of binary tree II - another method
Introduction and experience of wazuh open source host security solution
1.14 - 流水线
Time of process
中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章
做 SQL 性能优化真是让人干瞪眼
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
Overview of variable resistors - structure, operation and different applications
1.13 - RISC/CISC
Dichotomy, discretization, etc
随机推荐
Appium基础 — 使用Appium的第一个Demo
Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
leetcode-22:括号生成
4. 对象映射 - Mapping.Mapster
[practical skills] how to do a good job in technical training?
Leetcode-6108: decrypt messages
SPI 详解
redis发布订阅命令行实现
Scope of inline symbol
1.15 - 输入输出系统
wordpress切换页面,域名变回了IP地址
Groupbykey() and reducebykey() and combinebykey() in spark
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
1.13 - RISC/CISC
1040 Longest Symmetric String
Dichotomy, discretization, etc
LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
Introduction and experience of wazuh open source host security solution
2022 pole technology communication arm virtual hardware accelerates the development of Internet of things software
One question per day 1020 Number of enclaves