How to shrink a log file in Microsoft SQL server

SQL server is great, however sometimes the log files can become a bit "large" to say the least. In particular, if you don't have the log type set to simple for heavily transacted databases they can run into gigabytes which very quickly chomps up your disk space.

If you don't want such large log files for databases such as the ColdFusion client variables then you can actually truncate the logs quite easily. This could then be set up in a scheduled task to run every day or weekend.

In the example below, simply replace mydatabasename and mylogfilename with the actual database and log files you want. The value of 100 is the size of the log file you would be "happy with" having for the database. This will hold an obviously much smaller amount of transactions in case you needed to roll back:-

use master
Backup Log myDatabaseName With Truncate_Only
go
Use myDatabaseName
go
DBCC ShrinkFile (myLogFileName,100)
go

It's as simple as that..

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner