打赏

视图

参考彭泽江老师视频《sqlserver数据库学习》

纯手敲

视图=create view view_name as + sql语句

use zhangyanandb
GO
--新建视图查询所有教师表(接存储过程创建的库与表)
create view getteachers AS
select * from teacher
GO

--调用
select * from getteachers;

--更改视图
alter view getteachers AS
select name,subject from teacher
GO

--调用
select * from getteachers;

--删除
drop view getteachers
GO

--调用
select * from getteachers;

 

执行信息如下:

--调用
select * from getteachers
受影响的行: 0
时间: 0.021s

[SQL]

--更改视图
alter view getteachers AS
select name,subject from teacher

受影响的行: 0
时间: 0.021s

[SQL]

--调用
select * from getteachers
受影响的行: 0
时间: 0.021s

[SQL]

--删除
drop view getteachers

受影响的行: 0
时间: 0.021s

[SQL]

--调用
select * from getteachers
[Err] 42S02 - [SQL Server]对象名 'getteachers' 无效。

查询结果:

 

 

优点:封装复杂查询语句、减少网络传输

缺点:不能传参,可移植性低

posted @ 2018-04-02 20:04  每天都要学一点  阅读(129)  评论(0编辑  收藏  举报