Friday, August 11

Shrinking an SQL Server 2000 Transaction Log

I have a database in which the transaction log grew to 19GB, taking up the entire disk space on the server it was on, and which could not be shrunk. Most of the things I found on the net didn't shrink this very much.

However, I found the following script here which worked well, reducing it from 19GB to 52 MB.

http://www.thescripts.com/forum/thread79839.html


use database_name
go
create table shrinkfile(
col1 int,
col2 char(2048)
)

dump tran database_name with no_log
dbcc shrinkfile(logical_name_of_log, 50, TRUNCATEONLY)
go


set nocount on
declare @i int
declare @limit int

select @i = 0
select @limit = 10000

while @i < @limit
begin
insert into shrinkfile values(@i, 'Shrink the log...')
select @i = @i + 1
end

drop table shrinkfile