Skip to main content

Shrink Transaction Logs

You do NOT need to run this (I already did), but you might be interested in this SQL to shrink transaction logs. You do need to do a backup of the databases after you truncate them (I'm not concerned since these old databases are lookup only - no new data should be written to them).

USE MASTER
GO

BACKUP LOG
    file
WITH TRUNCATE_ONLY
GO

USE db
GO

DBCC SHRINKFILE ( 'dbfile' )
GO
USE Master
GO

I used the following code to generate the list of files in the database.

SELECT 'SELECT name from ' + rtrim ( name ) + '..sysfiles'
FROM sysdatabases
WHERE name LIKE 'dbfile%'
ORDER BY name

Don't forget to back-up the database once you're finished as well. A FULL database backup should be done!