批量删除MSSQL某个数据库中所有数据表
时间:2015-06-07 21:26:52 来源:xwidea.com 作者:xwidea.com 点击:1445次
在MSSQL(SQL Server)要删除一个数据库的所有数据表,如果这个数据库有几十或者几百个表的时候,而你又没有数据库服务器足够权限的时候,那么操作将会非常麻烦。
下面是批量删除MSSQL(SQL Server)中某个数据库所有表的批量处理办法:
在MSSQL(SQL Server)中运行下面的sql执行命令:
--删除所有约束
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
--删除数据库所有表
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) 网友评论
