视图定义
CREATE VIEW view_name[(column_list)]ASSELECT statement[WITH [CASCADED|LOCAL] CHECK OPTION]
示例:
create or replace view mt.cust_viewasselect * from mt.custwhere cust_sex='m'with check option;
修改
删除
DROP VIEW [IF EXISTS] view_name[,view_name]...[RESTRIC|CASCADE]
查看视图定义
SHOW CREATE VIEW mysql_test.cust_view;
更新视图数据
1、使用 insert 通过视图向基本表插入数据
INSERT INTO mysql_test.cust_viewVALUES(909,'张三','m','北京',null);
2、使用 update 语句通过视图修改基本表数据
update mysql_test.cust_viewset cust_address='上海市';
3、使用 delete 语句通过视图删除基本表数据
delete from mysql_test.cust_viewwhere cust_name='李四';
视图的优点
- 集中分散的数据
- 简化查询语句
- 重用 SQL 语句
- 保护数据安全
- 共享数据
- 更改数据的格式
