Friday, February 18, 2011

Shrink your SQL 2005 transaction log files

When the transaction log files are growing they take up a huge amount of disk space. So in our script to restore the environment, we've included a few T-SQL statements to set the recovery model to simple and shrink the transaction log files immediately. Here's the code, it might come in handy when you've got a database on your own machine as well.

USE [master]
GO
ALTER DATABASE [YourDatabase] SET RECOVERY SIMPLE WITH NO_WAIT
GO
USE [YourDatabase]
GO
DBCC SHRINKFILE (YourDatabase_log, 10)
GO


You don't want to set the recovery model to simple on critical databases! If you're not sure, just don't change the recovery model. Transactional replication uses the transaction log and if the service agent stops, all transactions are stored in the log to be synced later.

For more information:-