以下是引用片段
縮小SQL數據庫日記的大小
一般情況下
通過下面的這段批處理SQL程序序就可以實現了
注
SET NOCOUNT ON
DECLARE @LogicalFileName sysname
@MaxMinutes INT
@NewSize INT
USE dvbbs
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
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22048.html