方法一
一般情況下
方法二
SET NOCOUNT ON
DECLARE @LogicalFileName sysname
@MaxMinutes INT
@NewSize INT
USE tablename
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/22424.html