1. 为什么使用视图?
-
降低查询的复杂度,优化查询语句。
比如,在开发过程中如果经常在同一个查询语句上做查询,那么我们可以把这个查询语句封装起来做为一个视图表,那么下次可以直接在视图表中查。-- 比如两层嵌套查询 from ( select * from people join cart on(cart.pepople_id = people.id) where firstname = 'join' )a select a.lastname where a.id = 3; -- 此时可以优化:先创建视图表,再从视图表中查询 -- 1. 创建视图表 create view shorter_join as select * from people join cart on (cart.pepople_id = people.id) where firstname = 'join'; -- 2. 基于视图查询 select lastname from shorter_join where id = 3; -
可以选择将真实表中部分列数据提供给用户,提高数据安全。
--通过视图来限制数据访问可以用来保护信息不被随意查询: create table userinfo(firstname string, lastname string, ssn string, password string); create view safer_user_info as select firstname, lastname f

最低0.47元/天 解锁文章
6691






