SQL Server 如果视图存在执行删除

IF EXISTS(Select Name From Sysobjects Where Name='P_ExistsDropView' And Xtype='P')
DROP PROC P_ExistsDropView
GO
Create Proc P_ExistsDropView
(
@DelView Varchar(200)
)
As

Declare @SQLText Varchar(1000)
If Exists(Select Top 1 Name From Sysobjects Where Name=@DelView And XType='V') 
Begin
  Set @SQLText='Drop View ' + @DelView
  Exec(@SQLText)
End

 

调用方式:

Exec P_ExistsDropView 'View'

posted on 2013-04-17 14:48  哈哈哈哈BBA  阅读(4014)  评论(0编辑  收藏  举报

导航