SQL Server Log Truncation

Posted on June 23, 2015 by Destry Hines

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_Log, 1)
ALTER DATABASE [MyDb] SET RECOVERY FULL WITH NO_WAIT
GO

Posted in Uncategorized   Tagged sql, sql server, log, truncate