Truncating SQL Server Log Files

SQL Server logs in a circular fashion to its transaction log files. To shrink a transaction log file it is first necessary to backup the log.

The following script backs the log up, throwing away the backup in the process and then shrinks the files in the database. Make sure you have a full backup of the database before running.

declare @db varchar(50)
set @db = DB_NAME()

backup log @db with truncate_only
dbcc shrinkdatabase (@db, truncateonly)

This entry was posted in Sysadmin and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>