Thursday, May 3, 2012

T-SQL Script - Reduce log file of database

Sometimes I need to reduce log files of SQL Databases
This is the script which helps me:


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

No comments:

Post a Comment