Thursday, January 29, 2009

How to the Shrink Transaction Log?

Method 1:

Step 1.
To check transation log name:
(a) To check from database properties.
(b) Command:
select name from DBName.dbo.sysfiles

Step 2.
Use Master
go
BACKUP LOG DBName with truncate_only
go

Step 3.
USE DBName
go
dbcc shrinkfile (TranLogName,1) -- 1MB
go


Method 2: Re-attach DB with dropping transaction log.

Step 1. To run a full backup first.

Step 2. To detach the database.

EXEC sp_detach_db 'DBName'

Step 3. To delete the log file. OR to rename the existing log.

Step 4. To attach the database again.

EXEC sp_attach_db 'Kit', 'x:\full\path\to\db\file\Kit_Data.MDF'