I recently encountered a database that was 4 MB in size with it’s respective transaction log at 460 MB. The transaction log is used in a recovery model to restore the database to a point in time. I wanted to reduce the size of the transaction log. More importantly, I wasn’t exactly clear as to why a transaction log of that size was possible. It turns out that the transaction log had not been backed up for some time.
To reduce the size of the transaction log, the transaction log must be backed up first and then you can use shrink. This may be accomplished utilizing the SQL Query Analyzer
BACKUP LOG databasename WITH TRUNCATE_ONLY DBCC SHRINKFILE ( databasename_Log, 1)
Another source offered the following solution: (untested by me)
-
Right-click the database, choose Properties
-
Click Ok
-
Click Ok
Alternatively, the SQL to do it:
ALTER DATABASE mydatabase SET RECOVERY SIMPLE DBCC SHRINKFILE (mydatabase_Log, 1)
According to another source, “The first parameter is the so-called “logical name” of the log file (and not the physical name with the *.ldf extension). The second parameter (the zero), means to disregard the default “free space factor”, and shrink it to the maximum extent possible.”
DBCC SHRINKFILE (DataBaseName_Log, 0)