SQL Server Log Truncation

Sometimes the log files get filled up in SQL Server and you just need to clear them out to free up space. Usually you have to go through a backup process before you can truncate the logs but sometimes it’s not feasible or necessary to backup the logs. Here is a simple script to run that will truncate the log file:

USE [MyDb]
GO
ALTER DATABASE [MyDb] SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(MyDb_Log1)
ALTER DATABASE [MyDb] SET RECOVERY FULL WITH NO_WAIT
GO

 

Leave a Reply

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

five × 2 =