What is view?
Virtual views are relations that are defined by a query over other relations. They are not stored in the database, but can be queried as if they existed.
The view relation conceptually contains the tuples in the query result, but is not precomputed and stored. Instead, the database system stores the query expression associated with the view relation. Whenever the view relation is accessed, it tuples are created by computing the query result. Thus, the view relation is created whenever needed, on demand.
Advantages of view.
1. 视点集中
视图使得用户只需关心他们感兴趣的特定数据和他们所负责的特定任务。
2. 简化操作
视图大大简化了用户对数据的操作;在定义视图时,若视图本身就是一个复杂查询的结果集,这样在每一次执行相同的查询时,就不必重写这些复杂的查询语句,只要一条简单的查询视图语句即可。
3. 定制数据
视图能够实现让不同的用户以不同的方式来看相同的数据集。因此,当有许多不同的用户共用同一数据库时,这显得极为重要。
4. 合并分割数据
在有些情况下,由于表中数据量太大,故在表的设计时常将表进行水平分割或垂直分割,但表的结构的变化会对应用程序产生不良的影响。如果使用视图就可以重新保持原有的结构关系,从而使外模式保持不变,原有的应用程序仍可以通过视图来查询数据。
5. 安全性
视图可以作为一种安全机制;通过视图用户只能查看和修改他们所能看到的数据,其它数据库或表既不可见也不可以访问;如果某一用户想要访问视图的结果集,必须授予其访问权限。