Home  >  Article  >  Database  >  SQL存在性判断

SQL存在性判断

WBOY
WBOYOriginal
2016-06-07 17:46:391423browse

存在则删除


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

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

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn