转自:使用T-SQL语句操作视图
提示:只能查看,删除,创建视图,不能对数据进行增,删,改操作。
use StuManageDB
go
--判断视图是否存在
if exists(Select * from sysobjects where Name='View_ScoreQuery')
drop view View_ScoreQuery
go
--创建视图
create view View_ScoreQuery
as
select 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
go
select * from View_ScoreQuery
视图可以嵌套另外一个视图(尽量少套用)。