[sql]视图
视图
视图是一张虚拟的表,本质是一坨sql语句(可能是连表查询等非常复杂的一段sql)
- 模拟视图
select nid from partment where nid > 2; # 将它的结果作为下面一句的条件
select * from (select nid from partment where nid > 2) as A;
创建视图
create view v1 as
select man.name as mname,woman.name as wname from relationship
LEFT JOIN man on relationship.man_nid = man.nid
LEFT JOIN woman on relationship.woman_nid = woman.nid
where man.name = 'aaron'
查看视图(即一张表),会随着依赖的表动态更新的.
修改视图
alter view v1 as
select * from man where nid >= 1;
在查看视图,已动态更新了.
删除视图
drop view v1;