首页  >  文章  >  数据库  >  SQL存在性判断

SQL存在性判断

WBOY
WBOY原创
2016-06-07 17:46:391422浏览

存在则删除


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

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

 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn