删除数据库所有表和所有存储过程的SQL语句

发布时间:2013-11-29    发布:cenbel_ahai    分类:技术文档

--/第1步**********删除所有表的外键约束*************************/

DECLARE c1 cursor for
select 'alter table ['+ object_name(parent_obj) + '] drop constraint ['+name+']; '
from sysobjects
where xtype = 'F'
open c1
declare @c1 varchar(8000)
fetch next from c1 into @c1
while(@@fetch_status=0)
begin
exec(@c1)
fetch next from c1 into @c1
end
close c1
deallocate c1

--/第2步**********删除所有表*************************/

use 数据库
declare @tname varchar(8000)
set @tname=''
select @tname=@tname + Name + ',' from sysobjects where xtype='U'
select @tname='drop table ' + left(@tname,len(@tname)-1)
exec(@tname)

--/第3步**********删除所有存储过程*************************/

use 数据库
declare @tname varchar(8000)
set @tname=''
select @tname=@tname + Name + ',' from sysobjects where xtype='P'
select @tname='drop Procedure ' + left(@tname,len(@tname)-1)
exec(@tname)

查看 [2702]   评论 [0] 
相关标签: 程序开发 
文章评论
暂无数据!
我来说两句
昵 称:
评 论:
   
咨询电话:020-61136292 87569708 61004412 61004413
讯博官网 | 走进讯博 | 整合营销 | 案例解读 | 资讯中心 | 案例欣赏 | 产品体验区 | 客户如是说 | 联系我们
版权所有 © 2003-2014 广州讯博网络科技有限公司 粤ICP备08107356号 开心一刻
Website Design & Power by:Cenbel.com