復制代碼 代碼如下:
--====================================================================
-- 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)