复制代码 代码如下:
–====================================================================
— sql:数据库压缩语句
———————————————————————-
— description: 压缩数据库
— modify: x.zhong
–====================================================================
declare @db_name varchar(200)
–得到当前数据库名称
declare getdbname cursor for select db_name()
open getdbname
fetch getdbname into @db_name
while @@fetch_status = 0
begin
fetch getdbname into @db_name
end
close getdbname
deallocate getdbname
–压缩数据库日志
dump transaction @db_name with no_log
backup log @db_name with no_log
dbcc shrinkdatabase(@db_name)