Sunday, October 27, 2013

Simple SQL Query to Shrink SQL Server Database Log File Size

When SQL Server Service stopped working due to insufficient disk space, one of the possible culprit may be the SQL Server Database Log File that has grown to be very large.

Here is some simple SQL Query to shrink the size of the log file:

====
Use mydatabasename;
GO

ALTER DATABASE mydatabasename
SET RECOVERY SIMPLE
GO

DBCC SHRINKFILE (mydatabasename_Log, 1);
GO

ALTER DATABASE mydatabasename
SET RECOVERY FULL;
GO
====

Waring: The above query will truncate your database log!

No comments:

Post a Comment