- --判斷指定的數據庫是否存在,存在則刪除
- if exists (select name from master..sysdatabases where name in ('db_name'))
- drop database db_name
- --判斷指定的存儲過程是否存在,存在則刪除
- if exists (select * from sysobjects where objectproperty(object_id('proc_name'), 'IsProcedure')=1)
- drop procedure proc_name
- --判斷指定的表是否存在,存在則刪除
- if exists (select * from sysobjects where objectproperty(object_id('table_name'),'istable')=1)
- drop table table_name
- --判斷指定的自定義函數是否存在,存在則刪除
- if exists (select * from sysobjects where objectproperty(object_id('dbo.func_name'), 'isansinullson')=1)
- drop function dbo.func_name
- --判斷指定的臨時表是否存在,存在則刪除
- if exists (select * from tempdb..sysobjects where name like '#table_name%')
- drop table #table_name