Thursday, November 18, 2010

Truncate and shrink Transaction Log file in SQL Server 2008

SQL Server 2008

In SQL Server this process have been changed. In 2008, just change the recovery model to simple and then use DBCC Shrinkfile command.

use [YourDatabaseName]
select name,recovery_model_desc from sys.databases
GO
Alter database [YourDatabaseName] Set Recovery SIMPLE
GO
Declare @LogFileLogicalName sysname
select @LogFileLogicalName=Name from sys.database_files where Type=1
print @LogFileLogicalName

DBCC Shrinkfile(@LogFileLogicalName,1)



______________________________

If you may want to set the recovery back to Full. If so, add the following.
Alter database [YourDatabaseName] Set Recovery FULL