Archive for category Sql Server 2008

How to shrink DB log files

Execute the SQL script below to shrink the log files of your database to save some disk space

 

USE [DB Name];
GO
— Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE [DB Name]
SET RECOVERY SIMPLE;
GO
— Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE(‘DB Name_log’, 1)
DBCC SHRINKFILE(1, 1)
DBCC SHRINKFILE(2, 1)  — if there is a second ldf file
DBCC SHRINKFILE(3, 1) — if there is a third ldf file, and so on …..
GO
— Reset the database recovery model.
ALTER DATABASE [DB Name]
SET RECOVERY FULL;
GO

, ,

Leave a comment