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

520    Asked by dipesh_9001 in SQL Server , Asked on Jul 19, 2021

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:BackupTestDb.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. How sql server truncate transaction log?

Answered by Clare Matthews

The safest and correct way to truncate a log file if the database is in Full Recovery Mode is to do a Transaction Log Backup (without TRUNCATE_ONLY. This is going to be deprecated in future releases and is not advisable). It sounds like you want to shrink your log file afterwards, in which case you'd run a DBCC SHRINKFILE(yourTLogName) command. There is an optional second parameter for the requested size to shrink it to.

Here are the steps to Truncate the transaction log Right-click the database and select Properties -> Options.

  • Set the recovery model to Simple and exit the menu.
  • Right-click the database again and select Tasks -> Shrink -> Files.
  • Change the type to Log .
  • Under Shrink action, select Reorganize pages before releasing unused space and click OK.




Your Answer

Interviews

Parent Categories