当前位置: 首页> 文旅> 艺术 > MySQL-视 图

MySQL-视 图

时间:2025/8/26 15:36:07来源:https://blog.csdn.net/m0_74002833/article/details/140642743 浏览次数:0次

视 图

创建视图

视图是从一个或者几个基本表(或视图)导出的表。它与基 本表不同,是一个虚表。

语法:

create view 视图名 【view_xxx/v_xxx】

说明:

• view_name 自己定义的视图名;

• as 后面是这个视图说用到的查询结果;

# 视图
-- 视图只能用来查询,不能做增删改查
-- 创建视图
-- create view 视图名 【view_xxx/v_xxx】
-- as 查询语句
create view v_stu_man as
select * from student where ssex='男';

视图的操作

视图的查询

查询所有的视图

语法: select * from information_schema.VIEWS WHERE table_schema = ‘库名';

视图可以当作一张表来使用,所以用正 常的select查询即可

-- 查看库中所有的视图
select * from
information_schema.VIEWS 
WHERE table_schema = 'myschool'

查看视图的建立

语法:SHOW CREATE VIEW view_name

删除存储过程

语法:DROP VIEW view_name;

-- 删除视图
drop view v_stu_man

视图的作用

1.简化查询

2.重写格式化数据

3.频繁访问数据库

4.过滤数据

-- 视图使用
select * from v_stu_man;--
select * from v_stu_man vsm
left join class on vsm.classid=class.classidcreate view v_vstuman_class as
select v_stu_man.*,classname from v_stu_man 
left join class on v_stu_man.classid=class.classidselect * from v_vstuman_classupdate student set sname = '赵蕾蕾' where sid=1select * from student
关键字:MySQL-视 图

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: