How to Trim/Truncate a Database Log File

Prior to trimming/truncating your database log files, always ensure you have performed the necessary data backups steps for your data recovery workflows.

The job should first backup the database and then trim the log file.  You can do it with something like this…

DESTINIData Estimates database

Note: If your DESTINIData has your company name, then replace that only in the bold areas.

Step 1

BACKUP DATABASE [DESTINIData] TO DISK = 'D:\Path To Backups\DESTINIData.bak' WITH INIT    

GO

 Step 2

USE [DESTINIData]

GO

 ALTER DATABASE [DESTINIData] SET RECOVERY SIMPLE WITH NO_WAIT

DBCC SHRINKFILE([DESTINIData_Log], 0, TRUNCATEONLY) -- Don't change the file name here

ALTER DATABASE [DESTINIData] SET RECOVERY FULL WITH NO_WAIT

GO

Cost Database

Note: If your Cost database has your company name, then replace that only in the bold areas.

Step 1

BACKUP DATABASE [COSTDatabaseName] TO DISK = 'D:\Path To Backups\COSTDatabaseName.bak' WITH INIT    

GO

Step 2

USE [COSTDatabaseName]

GO

 ALTER DATABASE [COSTDatabaseName] SET RECOVERY SIMPLE WITH NO_WAIT

DBCC SHRINKFILE([COSTDatabaseName_Log], 0, TRUNCATEONLY)

ALTER DATABASE [COSTDatabaseName] SET RECOVERY FULL WITH NO_WAIT

GO

The COSTDatabaseName_Log name can be found by right-clicking on the database > Properties > Files > Logical Name