博客
关于我
MySQL 视图
阅读量:444 次
发布时间:2019-03-06

本文共 709 字,大约阅读时间需要 2 分钟。

数据库视图的概念是一个虚拟表,它本质上存储的是一组SQL查询语句。与数据库表类似,数据库视图由行和列组成,因此可以根据数据库表查询数据。大多数数据库管理系统(包括MySQL)都支持通过视图来访问基础表中的数据。

数据库视图的特点是动态的,因为它与物理表结构无关。数据库系统会将视图存储为一组连接语句。当基础表的数据发生变化时,视图也会反映这些变化。

数据库视图可以表示一个表的部分数据或多个表的综合数据。其结构和数据都是基于真实表的查询定义的。视图中的数据实际上是对真实表的引用。对视图中的数据进行增删改都会影响到真实的表。一个真实表可以创建多个视图。如果视图关联了多个表,则不允许进行增删操作,但单表可以增删改。视图通常由查询语句定义。

创建视图的语法通常是create view命令。例如:

create view VW_student_list asselect studentNo 学号, studentName 姓名, examScore 考试成绩from student swhere s.studentNo = r.studentNo;

查询视图的数据可以通过select * from VW_student_list完成。要删除视图,可以使用drop view命令。

要查看数据库中所有的视图,可以切换到information_schema库并执行select * from views。查看当前库的所有视图可以使用show tables命令并过滤结果。

在使用数据库视图时需要注意以下几点:视图可以查询多个表的数据,视图可以嵌套,但增删操作不能封装在视图中。对于关联多表的视图,删除操作有一定的限制。

转载地址:http://bdoyz.baihongyu.com/

你可能感兴趣的文章
Oracle:ORA-00911: 无效字符
查看>>
Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
查看>>
TCP基本入门-简单认识一下什么是TCP
查看>>
tableviewcell 中使用autolayout自适应高度
查看>>
Orcale表被锁
查看>>
svn访问报错500
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>
SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
查看>>