SQL 2005 Transaction Logs
Thank you.
declare @spid varchar(20)
declare cur CURSOR FOR
select spid
from sys.sysprocesses
where dbid = db_id('Your Database Name Here') /*<---Put your database name here*/
and spid > 50
open cur
fetch next from cur into @spid
while @@FETCH_STATUS = 0
BEGIN
exec ('kill ' + @spid)
fetch next from cur into @spid
END
close cur
deallocate cur
create table #Files
(FileName nvarchar(4000),
Depth int,
IsFile bit)
insert into #Files
exec xp_dirtree 'd:\', 1, 1
delete from #Files
where IsFile = 0
declare @FileName nvarchar(4000)
declare cur CURSOR FOR SELECT FileName from #Files
open cur
fetch next from cur into @FileName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @FileName = 'D:\Path\To\Your\Log\Backups\' + @FileName
RESTORE LOG YourDatabaseNameHere FROM DISK=@FileName WITH STANDBY='D:\Path\To\Your\StandBy\File.standby'
IF @@ERROR <> 0
exec xp_delete_file @FileName
fetch next from cur into @FileName
END
close cur
deallocate cur
Looking for relevant SQL Server Whitepapers? Visit the SearchSQLServer.com Research Library.
Mrdenny | Jun 9 2008 5:39AM GMT
Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.
Danyluk | Jun 10 2008 6:19PM GMT
Okay, thank you so much. I am going to look at this some more tonight and give it a try. The transaction logs do have the timestamps. I will let you know how it goes.