mssql里判断数据库对象是否存在的语句
1: --判断指定的数据库是否存在,存在则删除
2: if exists (select name from master..sysdatabases where name in ('db_name'))
3: drop database db_name
4: go
5:
6: --判断指定的存储过程是否存在,存在则删除
7: if exists (select * from sysobjects where objectproperty(object_id('proc_name'), 'IsProcedure')=1)
8: drop procedure proc_name
9: go
10:
11: --判断指定的表是否存在,存在则删除
12: if exists (select * from sysobjects where objectproperty(object_id('table_name'),'istable')=1)
13: drop table table_name
14: go
15:
16: --判断指定的自定义函数是否存在,存在则删除
17: if exists (select * from sysobjects where objectproperty(object_id('dbo.func_name'), 'isansinullson')=1)
18: drop function dbo.func_name
19: go
20:
21: --判断指定的临时表是否存在,存在则删除
22: if exists (select * from tempdb..sysobjects where name like '#table_name%')23: drop table #table_name
24: go