Total Pageviews

Thursday, March 27, 2014

How to empty a SQL Server database transaction log file

Sometimes the log file size is more than the db size. In my case, i have 3GB database and 10 GB log files which was occupying all my C drive space and i was not able to run any query against that database. So finally got a script to to truncate the transaction log which saved all my time and effort and the new log file size was 1 MB. Amazing!!

Please use the following script, hopefully you will also need it if you are a DB guy :)

USE DBName;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE DBName
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (DBName_log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE DBName
SET RECOVERY FULL;



No comments:

Post a Comment