Friday, October 01, 2004

Truncate SQL Server Database Log

Over time, the database log file can grow very large. In those cases, you might want to truncate the log to free up spaces. Here is how you can do it.

-- Truncate the log. It DOES NOT backup the log!!!
backup log testdb WITH NO_LOG

-- Shrink the log file
dbcc shrinkfile(database_logfile, truncateonly)

You can find out the name of your database log file by running the following stored proc:
EXEC sp_helpfile

After you truncate the log, the changes to the data are not recoverable. Make sure you always backup your database after truncating the log.



Post a Comment

<< Home