sql server 视图的操作

-- 判断要创建的视图名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[视图名]') and OBJECTPROPERTY(id, N'IsView') = 1)
-- 删除视图
drop view [dbo].[视图名]
GO

--例子:

--删除视图
drop view GetFinanceLogView
--创建视图
Create view GetFinanceLogView
WITH SCHEMABINDING
as
select ID,OutCashAccountNo ,InCashAccountNo,Amount,RemarkContent,Type,Status,AddTime,RunWater,OperationType from dbo.FinanceLog

--建立索引
if (exists (select * from sys.indexes where name = 'idx_prod_ProductProgress_Sht'))
drop index GetFinanceLogView.idx_prod_ProductProgress_Sht
go
create UNIQUE CLUSTERED index idx_prod_ProductProgress_Sht
on
GetFinanceLogView(ID);

原文地址:https://www.cnblogs.com/yangjinwang/p/4205859.html