T-SQL 视图

 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 建议在调用视图的时候加

上一篇:C# winform自定义Label控件使其能设置行距


下一篇:使用apache和nginx代理实现tomcat负载均衡及集群配置详解