Tag Archives: mssql


How to shrink Microsoft SQL log files

When having Microsoft SQL databases, its log files can grow quite a bit, potentially slow down the database server and eat up disk space.

To shrink a database, one can run the following line:

EXEC D_ShrinkDBLogs 0,100,1000,'with truncate_only','DB_NAME'
(change DB_NAME with the database’s name)

To shrink all databases, one can use “sp_MSforeachdb” which is an undocumented sql stored procedure:

EXEC sp_MSForEachDB 'D_ShrinkDBLogs 0,100,1000,''with truncate_only'',''?'''

To run this, the following stored procedure need to be installed. It can just be copy pasted from the code below (or download from this link):
read more »