存在判断

--判断指定的数据库是否存在,存在则删除

 

if exists (select name from master..sysdatabases where name in (''db_name''))

 

drop database db_name

 

go

 

--判断指定的存储过程是否存在,存在则删除

 

if exists (select * from sysobjects where objectproperty(object_id(''proc_name''), ''IsProcedure'')=1)

 

drop procedure proc_name

 

go

 

--判断指定的表是否存在,存在则删除

 

if exists (select * from sysobjects where objectproperty(object_id(''table_name''),''istable'')=1)

 

drop table table_name

 

go

 

--判断指定的自定义函数是否存在,存在则删除

 

if exists (select * from sysobjects where objectproperty(object_id(''dbo.func_name''), ''isansinullson'')=1)

 

drop function dbo.func_name

 

go

 

--判断指定的临时表是否存在,存在则删除

 

if exists (select * from tempdb..sysobjects where name like ''#table_name%'')

 

drop table #table_name

 

go

 

 

 

文章出处:http://www.diybl.com/course/7_databases/sql/sqlServer/2008515/116800.html

原文地址:https://www.cnblogs.com/LeimOO/p/1417027.html