use StudentManager
go
--判断视图是否存在
if exists(select * from sysobjects where name='view_ScoreQuery')
drop view view_ScoreQuery
go
--创建视图
create view view_ScoreQuery
as
select top 1000 Students.StudentId,StudentName,ClassName,
C#=CSharp,SQLDB=SQLServerDB,
ScoreSum=(CSharp+SQLServerDB) from Students
inner join ScoreList on Students.StudentId=ScoreList.StudentId
inner join StudentClass on Students.ClassId=StudentClass.ClassId
order by StudentClass.ClassId
go
--使用视图查询
select * from view_ScoreQuery
视图里面如果想用order by 排序,必须要加入top,所以视图里不建议加order by ,想要加order by 建议在调用视图的时候加