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

Advertisements

, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: