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判斷