SQL Server 如果表存在执行删除

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

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

调用方式:

Exec P_ExistsDropTable 'Table'

这样就不用每次要删除一个表都要写SQL判断

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

导航