SQL:数据库压缩语句(存档)
--===================================================================
--SQL:数据库压缩语句
-------------------------------------------------------------------
DECLARE @db_name varchar(200)
------------如果压缩某一个数据库用下面一句(已测试)--------------
set @db_name='RedfDB01' --数据库名
-----------------------------------------------------------------
-------------如果压缩所有数据库用下面几句(好像是,没有测试)-------
--得到当前数据库名称---------
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)