操作環境
任務描述
我有一個數據庫
這個日志的大小為
操作如下
在查詢分析器裡面
SET NOCOUNT ON
DECLARE @LogicalFileName sysname
@MaxMinutes INT
@NewSize INT
USE Cisi
SELECT @LogicalFileName =
@MaxMinutes =
@NewSize =
DECLARE @OriginalSize int
SELECT @OriginalSize = size
FROM sysfiles
WHERE name = @LogicalFileName
SELECT
CONVERT(VARCHAR(
CONVERT(VARCHAR(
FROM sysfiles
WHERE name = @LogicalFileName
CREATE TABLE DummyTrans
(DummyColumn char (
DECLARE @Counter INT
@StartTime DATETIME
@TruncLog VARCHAR(
SELECT @StartTime = GETDATE()
@TruncLog =
DBCC SHRINKFILE (@LogicalFileName
EXEC (@TruncLog)
WHILE @MaxMinutes > DATEDIFF (mi
AND @OriginalSize = (SELECT size FROM sysfiles WHERE name =
@LogicalFileName)
AND (@OriginalSize *
BEGIN
SELECT @Counter =
WHILE ((@Counter < @OriginalSize /
BEGIN
INSERT DummyTrans valueS (
DELETE DummyTrans
SELECT @Counter = @Counter +
END
EXEC (@TruncLog)
END
SELECT
CONVERT(VARCHAR(
CONVERT(VARCHAR(
FROM sysfiles
WHERE name = @LogicalFileName
DROP TABLE DummyTrans
SET NOCOUNT OFF
執行結果
Original Size of Cisi LOG is
Final Size of Cisi LOG is
數據庫日志已成功地收縮為
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22054.html