Monday, September 19, 2011

Transaction Log issue for SQL Server

-- View Transaction log
DBCC Log(myDbName)




If the recovery model is set to SIMPLE the log data will be cleared automatically.

-- How to Change Recovery Model to simple
use myDbName
-- Change Recovery model to simple
ALTER DATABASE
myDbName SET RECOVERY SIMPLE
-- enable auto shrink option
ALTER DATABASE
myDbName SET AUTO_SHRINK ON
-- Shrink DB Log file
DBCC SHRINKFILE(
myDbName_log, TRUNCATEONLY)

-- This command help you to find out what is database log file name
USE myDbName
SELECT * FROM sys.database_files