Script to Shrink Log FilesThis script will take the name of a specific log file, its database, and a desired file size, and will then proceed to compress the given log file. All that needs to be entered is the "tx-logname", "DESIRED_FINAL_SIZE_IN_MB", and "basename". Author: Conrado Pacheco DBCC SHRINKFILE (<tx-logname> , <DESIRED_FINAL_SIZE_IN_MB>,TRUNCATEONLY ) go BACKUP LOG <basename> WITH TRUNCATE_ONLY godrop table mytable goCREATE TABLE MyTable (MyField VARCHAR(10), PK INT ) INSERT Mytable (PK) VALUES (1) GO SET NOCOUNT ON DECLARE @Index INT SELECT @Index = 0 WHILE (@Index < 20000) BEGIN UPDATE MyTable SET MyField = MyField WHERE PK = 1 /* Some criteria to restrict to one row. */ SELECT @Index = @Index + 1 END SET NOCOUNT OFF goDBCC SHRINKFILE ( <tx-logname> ,<DESIRED_FINAL_SIZE_IN_MB>, truncateonly ) go BACKUP LOG < basename > WITH TRUNCATE_ONLY go
用它可以减小ldf文件的大小的
DBCC SHRINKFILE (<tx-logname> , <DESIRED_FINAL_SIZE_IN_MB>,TRUNCATEONLY )
go
BACKUP LOG <basename> WITH TRUNCATE_ONLY
godrop table mytable
goCREATE TABLE MyTable (MyField VARCHAR(10), PK INT )
INSERT Mytable (PK) VALUES (1)
GO
SET NOCOUNT ON
DECLARE @Index INT
SELECT @Index = 0
WHILE (@Index < 20000)
BEGIN
UPDATE MyTable
SET MyField = MyField
WHERE PK = 1 /* Some criteria to restrict to one row. */
SELECT @Index = @Index + 1
END
SET NOCOUNT OFF
goDBCC SHRINKFILE ( <tx-logname> ,<DESIRED_FINAL_SIZE_IN_MB>, truncateonly )
go
BACKUP LOG < basename > WITH TRUNCATE_ONLY
go