Wednesday, May 29, 2013

Reduce the size SQL Server 2008 Log file

This is a very common problem, the log file on SQL Server may grow excessively and it may even fill a small server. On previous versions of SQL Server the problem was a little harder to manage, but since version 2008 reducing the size of this file can be achieve with this little script, 100% guaranteed:

Use my_db
GO
 
Alter Database my_db Set Recovery Simple
GO

Alter Database mi_db Set Recovery Full
GO

DBCC SHRINKFILE ('my_db_log', 1)
GO

Where "my_db" is the name of our database and "my_db_log" is the name of the log of your database, If you dont know it you can check it on the properties of the database.

I hope you can find this useful.