当前位置:网站首页>Views in MySQL
Views in MySQL
2022-06-22 13:22:00 【Xiaotiantian 666】
A view is a virtual table . The data in the view does not actually exist in the database , Row and column data comes from tables used in queries in the definition view , And it's dynamically generated when using views .
Generally speaking , The view only saves the of the query SQL Logic , Do not save query results . So when we create views , The main job is to create this SLQ On the query statement .
- establish
CREATE [OR REPLACE] VIEW View name [( List of names )] AS SELECT sentence [WITH [CASCADED | LOCAL] CHECK OPTION] - Inquire about
View the create view statement :SHOW CREATE VIEW View name ;
View view data :SELECT * FROM View name .....; - modify
Mode one :CREATE [OR REPLACE] VIEW View name [( List of names )] AS SELECT sentence [WITH [CASCADED | LOCAL] CHECK OPTION]
Mode two :ALTER VIEW View name [( List of names )] AS SELECT sentence [WITH [CASCADED | LOCAL] CHECK OPTION] - Delete
DROP VIEW [IF EXISTS] View name [, View name ]...;
Check options for view
When using WITH CHECK OPTION Clause when creating a view ,MySQL Each row that is changing is checked through the view , for example : Insert 、 to update 、 Delete , To make it conform to the definition of the view .MySQL Allows you to create a view based on another view , It also checks the rules in the dependency view for consistency . In order to determine the scope of inspection ,mysql There are two options :
CASCADED and LOCAL, The default value is CASCADED.
Update of view
To make the view updatable , There must be a one-to-one relationship between the rows in the view and the rows in the underlying table . If the view contains any of the following , The view is not updatable :
1、 Aggregate function or window function (sum()、min()、max()、count() etc. )
2、DISTINCT
3、GROUP BY
4、HAVING
5、UNION perhaps NUION ALL
The function of view
- Simple
Views not only simplify the user's understanding of the data , They can also simplify their operations . Queries that are often used can be defined as views , Thus, the user does not have to specify all the conditions for each subsequent operation . - Security
The database can authorize , However, it cannot be authorized to specific rows and columns in the database . Through view users can only query and modify the data they can see - Data independence
View can help users shield the impact of changes in real table structure .
边栏推荐
- MySQL中触发器
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
- 130. Surrounded Regions
- RobotFramework中setUp的小技巧
- 46. Permutations
- leetcode-二分法
- Mysql中的锁
- Detailed installation tutorial of MySQL 8.0.29 under windows to solve the problem that vcruntime140 cannot be found_ 1.dll、plugin caching_ sha2_ password could not be loaded
- 6月《中国数据库行业分析报告》发布!智能风起,列存更生
- leetcode 1579. Ensure that the graph can be completely traversed
猜你喜欢

MySQL 5.7 + Navicat download and installation tutorial (with installation package)

leetcode-二分法

leetcode 1579. Ensure that the graph can be completely traversed

Set up your own website (5)

redis修改密码,及启动、查看等操作

130. Surrounded Regions

Reddit product director: a practical guide for NFT members for Web3 creators

leetcode LCP 10. Binary tree task scheduling

leetcode LCP 10. 二叉树任务调度

Windows system installs multiple MySQL versions (without uninstalling the original version), and the old and new versions are compatible.
随机推荐
769. Max Chunks To Make Sorted
Windows system installs multiple MySQL versions (without uninstalling the original version), and the old and new versions are compatible.
leetcode LCP 10. Binary tree task scheduling
微信支付二维码生成
leetcode 834. 树中距离之和
Redis
310. Minimum Height Trees
RobotFramework二次开发——Socket推送实时日志
260. Single Number III
Making rectangular border according to metric system through PostGIS
240. Search a 2D Matrix II
46. Permutations
阿里云磁盘性能分析
338. Counting Bits
基于JSP的图书馆管理系统,包含源码,数据库脚本,项目运行视频教程,毕设论文撰写视频教程
leetcode 85. 最大矩形
使用SQLAlchemy进行组合分页查询
130. Surrounded Regions
Gradle notes
Testing methodology - data driven testing