Showing posts with label SQL server. Show all posts
Showing posts with label SQL server. Show all posts

Wednesday, June 25, 2008

shrinking SQL database log file

use master
go

ALTER DATABASE urDataBaseName SET RECOVERY Simple --to alter the database to simple mode to accept shrinking

BACKUP LOG urDataBaseName WITH TRUNCATE_ONLY --to backup the log file before shrinking

use urDataBaseName
go

DBCC SHRINKFILE (urDataBaseName_log, TRUNCATEONLY) --shrinking the log

use master
go

SELECT * FROM sys.dm_tran_session_transactions --check on the operation

ALTER DATABASE urDataBaseName SET RECOVERY Full --reset first line

-- and if it gives you an error says cannot locate file urDataBaseName_log in sysfiles ... It could be an issue with the logical file name so make sure that the logical file name is as the physical file name.