首页 > 代码库 > 20141110--SQL视图
20141110--SQL视图
--------------------------视图-----------------------视图是一个虚拟表,数据来自于原表,原表的数据改变,视图也会改变select Student.Sno,sname,ssex,class,cno,degree from Student join Score on Student.Sno=Score.Sno --以下代码由系统自己生成,在左边的对象管理器中,右键视图-新建视图SELECT dbo.Student.Sno AS Expr2, dbo.Student.Sname AS Expr3, dbo.Student.Ssex AS Expr4, dbo.Student.Sbirthday AS Expr5, dbo.Student.Class AS Expr6, dbo.Score.Cno AS Expr7, dbo.Score.Degree AS Expr8FROM dbo.Student INNER JOIN dbo.Score ON dbo.Student.Sno = dbo.Score.Sno------------------------------------------用代码生成视图--只能有表连接 join on, 不能出现聚合函数,等等create view St_Scasselect Student.Sno,sname,ssex,class,cno,degree from Student join Score on Student.Sno=Score.Sno ----------查询视图select *from St_Sc-----------------------不用 join oncreate view sscasselect Student.Sno,Sname,Ssex,Sbirthday,Class,Score.Cno,Cname,Tno,Degree from Student,Course,Score where Student.Sno=Score.Sno and Score.Cno=Course.Cno------------------使用 join oncreate view sssasselect Student.Sno,Sname,Ssex,Sbirthday,Class,Score.Cno,Cname,Tno,Degree from Score join Course on Score.Cno=Course.Cnojoin Student on Student.Sno=Score.Snoselect *from sscselect *from sss------------修改视图----需要重写,相当于删掉重建alter view sssasselect Student.Sno,Sname,Ssex,Class,Score.Cno,Cname,Tno,Degree from Score join Course on Score.Cno=Course.Cnojoin Student on Student.Sno=Score.Sno
查询视图结果:
20141110--SQL视图
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。