1. 程式人生 > >使用T-SQL語句操作視圖

使用T-SQL語句操作視圖

word tail 分享 判斷 from eat student span ref

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

技術分享圖片

視圖可以嵌套另外一個視圖(盡量少套用)。

使用T-SQL語句操作視圖