使用T-SQL语句操作视图

转自:使用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

这里写图片描述

视图可以嵌套另外一个视图(尽量少套用)。

posted @ 2018-05-02 18:38  习惯沉淀  阅读(1686)  评论(0编辑  收藏  举报