复制代码 代码如下:
alter database 数据库名
set recovery simple
go
dbcc shrinkdatabase (数据库名)
go
alter database 数据库名
set recovery full
go
复制代码 代码如下:
create procedure shrinkDatabase
as
declare @name nvarchar(2000)
declare getDataBaseCursor cursor for
select name from sysdatabases //取出所有库名
open getDataBaseCursor
fetch next from getDataBaseCursor
into @name //将取出来的值放在一个变量中
while @@fetch_status=0 //根据值循环执行压缩
begin
exec ('alter database '+ @name+' set recovery simple')
exec ('dbcc shrinkdatabase('+@name+')')
exec ('alter database'+@name+' set recovery full')
fetch next from getDataBaseCursor
into @name end
close getDataBaseCursor //关闭
deallocate getDataBaseCursor //释放
sp_helpdb urltest //比对数据库大小
exec shrinkDatabase //执行
新闻热点
疑难解答