Home > Database > Mysql Tutorial > body text

mysql5.0.1提供视图功能其优势

WBOY
Release: 2016-06-07 16:41:53
Original
1181 people have browsed it

视图相对于普通的表的优势有以下几点: 1、简单:使用视图的用户完全不需要关心后面对应的表结构、关联条件和筛选条件,对用户来说视图已经过滤好复合条件的结果集 2、安全:使用视图的用户只恩呢该访问他们被允许查询的结果集,对表的权限管理并不能限制多

视图相对于普通的表的优势有以下几点:

1、简单:使用视图的用户完全不需要关心后面对应的表结构、关联条件和筛选条件,对用户来说视图已经过滤好复合条件的结果集

2、安全:使用视图的用户只恩呢该访问他们被允许查询的结果集,对表的权限管理并不能限制多某个行某个列,但是通过视图可以简单的实现

3、数据独立:一旦视图的结构定义了,可以屏蔽表的结构变化对用户的影响,源表增加列对视图没有影响;源表修改列名,则只用通修改视图定义来适应变化,不会对访问者造成影响。

The view definition is “frozen” at creation time, so changes to the
underlying tables afterward do not affect the view definition. For
example, if a view is defined as SELECT * on a table, new columns added
to the table later do not become part of the view.

这点挺重要的,就是视图定义是会冻结的,比如我们使用select *来创建视图后,然后在通过alter table 添加字段后,这个后续添加的字段不会体现在原来视图上。

mysql> create view v_tchar as select * from tchar;

经过查询information_schema中的views发现,通过select *来定义的视图,会被转换成如下:
mysql> select * from views \G
*************************** 1. row ***************************
TABLE_CATALOG: NULL
TABLE_SCHEMA: liufofu
TABLE_NAME: v_tchar
VIEW_DEFINITION: select `liufofu`.`tchar`.`t1` AS `t1`,`liufofu`.`tchar`.`t2` AS `t2`,`liufofu`.`tchar`.`t3` AS `t3`,`liufofu`.`tchar`.`t4` AS `t4` from `liufofu`.`tchar`
CHECK_OPTION: NONE
IS_UPDATABLE: YES
DEFINER: root@localhost
SECURITY_TYPE: DEFINER
CHARACTER_SET_CLIENT: latin1
COLLATION_CONNECTION: latin1_swedish_ci
1 row in set (0.01 sec)

所以后续添加的字段不会体现在原定义的视图上。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!