当前位置:网站首页>【mysql学习笔记26】视图
【mysql学习笔记26】视图
2022-07-01 07:30:00 【yqs_281876918】
创建视图
CREATE VIEW view_name[(col1,col2,…)] AS SELECT语句 [WITH [CASCADED|LOCAL] CHECK OPTION];
查询视图
查看创建语句
show create view 视图名;
查询
select * from 视图名;
修改视图
方式一
CREATE OR REPLACE VIEW view_name[(col1,col2,…)] AS SELECT语句 [WITH [CASCADED|LOCAL] CHECK OPTION];
方式二
ALTER VIEW 视图名(列明列表) AS SELECT语句 [WITH [CASCADED|LOCAL] CHECK OPTION];
删除视图
DROP VIEW [IF EXISTS] 视图名;
插入
对视图进行插入会插入原表中
检查选项
当使用WITH CHECK OPTION子句创建视图时,MySQL会通过视图检查正在更改的每个行,例如插入,更新,删除,以使其符合视图的定义。MySQL允许基于另一个视图创建视图,它还会检查依赖视图中的规则以保持一致性。为了确定检查的范围,mysql提供了两个选项:CASCADED和LOCAL,默认值为CASCADED。
无with check option时,是不需要满足当前视图的条件的。并且对于底部视图(即该视图针对的视图),先判断底部视图是否有with check option语句,有的话,按照其规则(local或者cascaded)处理,没有的话则不需要满足底部视图的条件。
with local check option时,需要满足当前视图的条件。对于底部视图,也是先看是否有指定的with check option语句,有的话对应处理,无则不需要满足底部视图的条件。
with cascaded check option(cascaded可以省略)时,需要满足当前视图的条件。并且对于所有底部视图的条件,也需要一并满足,哪怕底部视图没有定义with check option语句。
更新
要使得视图可更新,那么视图的列必须和原表的列一一对应
边栏推荐
- 她就是那个「别人家的HR」|ONES 人物
- 华泰证券开户是安全可靠的么?怎么开华泰证券账户
- [microservice openfeign] feign's log record
- 2022电工(中级)复训题库及答案
- 热烈祝贺五行和合酒成功挂牌
- 【R语言】两个/N个数据合并merge函数
- Redisson uses the complete solution - redisson official documents + Notes (Part 1)
- C# Newtonsoft. Use of job in JSON
- Cadence OrCAD Capture “网络名”相同,但是未连接或连接错误的解放方案之nodename的用法
- Vscode automatically formats code according to eslint specification
猜你喜欢
C# 读写自定义的Config文件
赌上了绩效,赢了公司CTO,我要搭DevOps平台!
Why are so many people turning to product managers? What is the development prospect of product manager?
[lingo] solve quadratic programming
JAX的深度学习和科学计算
关于图灵测试和中文屋Chinese room的理解
Unity2021-Scene视图中物体无法直接选中的解决办法
2022 test question bank and simulation test of tea master (primary) operation certificate
2022危险化学品经营单位主要负责人试题及模拟考试
ctfshow-web354(SSRF)
随机推荐
电脑有网络,但所有浏览器网页都打不开,是怎么回事?
I bet on performance and won the CTO of the company. I want to build Devops platform!
[recommendation system] breakthrough and imagination of deep location interactive network dpin for meituan takeout recommendation scenario
JAX的深度学习和科学计算
go-etcd
[R language] two /n data merge functions
如何让两融交易更极速
[classification model] Q-type cluster analysis
2022 mobile crane driver test exercises and online simulation test
北漂程序员深夜emo发帖求助:女朋友走了我很孤独 ......
ctfshow-web351(SSRF)
redisson使用全解——redisson官方文档+注释(下篇)
【编程强训3】字符串中找出连续最长的数字串+数组中出现次数超过一半的数字
Redisson utilise la solution complète - redisson Documents officiels + commentaires (Partie 1)
ctfshow-web355,356(SSRF)
redisson使用全解——redisson官方文档+注释(上篇)
ctfhub-端口扫描(SSRF)
2022 tea master (intermediate) recurrent training question bank and answers
kubernetes资源对象介绍及常用命令(二)
Is it safe to do fund fixed investment on Great Wall Securities?