How to truncate the database log files in sql server?

USE <Give DB Name Here>;

GO
— Truncate the log by changing the database recovery model to SIMPLE.

SELECT Name ,Size/128.0 – CAST(FILEPROPERTY(Name, ‘SpaceUsed’) AS int)/128.0 AS ‘Available Space In MB’
FROM sys.database_files;

ALTER DATABASE <Give DB Name Here>

SET RECOVERY SIMPLE;

GO

— Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (<Give DB Name Here>_log, 1);

GO

— Reset the database recovery model.

ALTER DATABASE <Give DB Name Here>

SET RECOVERY FULL;

GO

Advertisements