Wednesday, May 04, 2016

Truncate log without backup

So often in the non production environments we require the database logs to be truncated and the backup in these cases really does not matter.

As the truncate only option has been removed by Microsoft to avoid misuse of the command, there still is a workaround to shrink the transcation log without having to actually back it up.

The trick is to backup the log to a nul disk as shown below
BACKUP LOG MicrosoftDynamicsAX_model TO DISK='NUL:'
dbcc shrinkfile( MicrosoftDynamicsAX_model_log, 0 )
BACKUP LOG MicrosoftDynamicsAX TO DISK='NUL:'
dbcc shrinkfile( MicrosoftDynamicsAX_log, 0 )

No comments: