--删除数据库
if exists(select * from sys.databases where name = 'DBTEST')
drop database DBTEST
use DBTEST --切换当前数据库为DBTEST
--删除表(先判断表在当前数据库是否存在,存在则删除,其中type='U'判断对象类型为用户定义表类型)
if exists(select * from sys.objects where name = 'Department' and type = 'U')
drop table Department
--删除约束
if exists(select * from sysobjects where name=约束名)
alter table 表名 drop constraint 约束名;
go
--删除存储过程;删除索引同
if exists(select name from sysobjects where name='tri_sc')
begin
drop procedure tri_sc
print '已删除'
end
else
print '不存在,可创建!