--SQL2008將日志文件收縮到指定的目標(biāo)大小
--以下示例將 enjoy_store數(shù)據(jù)庫中的日志文件收縮到 1 MB。
--若要允許 DBCC SHRINKFILE 命令收縮文件,首先需要通過將數(shù)據(jù)庫恢復(fù)模式設(shè)置為 SIMPLE 來截?cái)嘣撐募?/font>
USE enjoy_store;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE enjoy_store
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (enjoy_store_log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE enjoy_store
SET RECOVERY FULL;
GO
補(bǔ)充一下:
/*
使用命令 DBCC SHRINKFILE 收縮單個(gè) tempdb 文件。DBCC SHRINKFILE 比 DBCC SHRINKDATABASE 提供更多的靈活性,
因?yàn)槟梢詫蝹(gè)數(shù)據(jù)庫文件使用它而不必影響屬于同一數(shù)據(jù)庫的其他文件。DBCC SHRINKFILE 接收 target size 參數(shù),
這是所需的數(shù)據(jù)庫文件的最終大小。
重要說明:必須在 tempdb 數(shù)據(jù)庫不發(fā)生任何活動時(shí)運(yùn)行 DBCC SHRINKFILE 命令。
要確保在執(zhí)行 DBCC SHRINKFILE 時(shí)其他進(jìn)程不能使用 tempdb,必須以單用戶模式重新啟動 SQL Server。
有關(guān) DBCC SHRINKFILE 的更多信息,請參見本文中在使用 Tempdb 時(shí)執(zhí)行 DBCC SHRINKDATABASE 或 DBCCSHRINKFILE 的結(jié)果 一節(jié)。
確定主數(shù)據(jù)文件 (tempdb.mdf)、日志文件 (templog.ldf) 和/或添加到 tempdb 的其他文件的所需大小。
確保在這些文件中使用的空間小于或等于所需的目標(biāo)大小。 用查詢分析器連接到 SQL Server,
然后為需要收縮的特定數(shù)據(jù)庫運(yùn)行下列 Transact-SQL 命令:
*/
use tempdb
go
dbcc shrinkfile (tempdev,5)
go
-- this command shrinks the primary data file
dbcc shrinkfile (templog,1)
go
-- this command shrinks the log file, look at the last paragraph.
可以收縮數(shù)據(jù)庫enjoy_shq_1.mdf文件