Home » Programming / Coding

Truncate MS SQL 2008 Database Log File

16 September 2009 1,699 views No Comment
If you need to truncate the SQL database log files to keep them smaller in size. The process I am demonstrating here is for MS SQL 2008.–Get in the database

use Test
GO

–see current file sizes
SELECT name,size from sys.database_files

–see current recovery model
select name,recovery_model_desc from sys.databases

–According to the articles if you switch the Recovery Model to Simple inactive part of the transaction log should be removed in MS SQL 2008.
–This command will reduce the log file somewhat
Alter database Test SET Recovery simple

–check if the recovery model is changed
select name,recovery_model_desc from sys.databases

–check file sizes
select name,size from sys.database_files

–changing the recovery model to Simple might not reduce the size enough. to reduce it further
DBCC SHRINKFILE (N’Test_log’ , 1)

–check file size
select name,size from sys.database_files

Source: http://www.bostonwebdeveloper.com/2009/09/truncate-ms-sql-2008-database-log-file/

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.