Tuesday, 26 January 2016

MS SQL Server - Shrinking transaction logs

Shrinking transaction logs

Run the script below to shrink the database's transaction log. Please note that logs should not really need to be shrank. If logs are not needed, on the database options set the database recovery model to simple this process (see below).

MS SQL Server 2005 

use database_name

backup log progress with truncate_only
dbcc shrinkfile ('transaction_logical_filename')


MS SQL Server 2008 and above

Microsoft SQL Server 2008 does not support the backup with truncate_only directive. So to truncate a log in 2008, run the following script.

BACKUP LOG database_name TO DISK='NULL'

Please endure that the database recovery model is set to full (see below) and a database full back up has been run.

Database option screen - opened by right clicking on the database, and selecting database options.




 



No comments:

Post a Comment