HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How do I truncate the transaction log in a SQL Server 2008 database?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
the2008logsqldatabasetruncatetransactionhowserver

Problem

How do I truncate the transaction log in a SQL Server 2008 database?

What are possible best ways?

I tried this from a blog as follows:


1) From the setting database to simple recovery, shrinking the file
and once again setting in full recovery, you are in fact losing your
valuable log data and will be not able to restore point in time. Not
only that, you will also not be able to use subsequent log files.


2) Shrinking database file or database adds fragmentation.


There are a lot of things you can do. First, start taking proper log backup using
the following command instead of truncating them and
losing them frequently.

BACKUP LOG [TestDb] TO  DISK = N'C:\Backup\TestDb.bak'
GO



Remove the code of SHRINKING the file. If you are taking proper log
backups, your log file usually (again usually, special cases are
excluded) do not grow very big.

Solution

You could backup the log to the null device:

backup log [databasename] to disk = 'nul';


Or you could switch the recovery model to simple and then back to full/bulk again.

Code Snippets

backup log [databasename] to disk = 'nul';

Context

StackExchange Database Administrators Q#6996, answer score: 8

Revisions (0)

No revisions yet.