https://www.cnblogs.com/geaozhang/p/6792369.html#chuangjianshitu
视图(view)是一种虚拟存在的表,是一个逻辑表,本身并不包含数据。作为一个select语句保存在数据字典中的。
1 .创建视图
mysql> desc tabletest; #查看表。+-------+---------------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+---------------------------+------+-----+---------+----------------+| id | int(11) unsigned zerofill | NO | PRI | NULL | auto_increment || name | char(20) | YES | | NULL | || age | int(11) | YES | | NULL | |+-------+---------------------------+------+-----+---------+----------------+
创建view
create view view_hello(id,name,age) as select id,name,age from tabletest where age="18" with check option; show create veiw;
查看视图
mysql> select * from view_hello;+-------------+------+------+| id | name | age |+-------------+------+------+| 00000000001 | meng | 18 || 00000000002 | meng | 18 || 00000000003 | meng | 18 || 00000000004 | meng | 18 || 00000000005 | meng | 18 || 00000000006 | meng | 18 || 00000000007 | meng | 18 || 00000000008 | meng | 18 |+-------------+------+------+8 rows in set (0.00 sec)
[WITH [CASCADED | LOCAL] CHECK OPTION]:表示视图在更新时保证在视图的权限范围之内
cascade是默认值,表示更新视图的时候,要满足视图和表的相关条件
local表示更新视图的时候,要满足该视图定义的一个条件即可
TIPS:推荐使用WHIT [CASCADED|LOCAL] CHECK OPTION选项,可以保证数据的安全性
基本格式:
基本格式:
create view <视图名称>[(column_list)]
as select语句
with check option;