There are  a variety of reasons why a DBA might want to perform log restores, maybe as part of recovery or maybe to set up mirroring.

The basic syntax for a log restore is as follows

RESTORE LOG database_name FROM DISK = 'Location' (with norecovery)

This is fine for restoring one log backup but if you’ve got maybe 12 hours worth of log backups that’s a pain.

Below is a quick and dirty script which will generate the T-SQL which when run will restore the logs from a point in time. Think of this like quick and dirty T-SQL script generation. You could even plug this into dynamic SQL.

declare @database_name as nvarchar(20)
set @database_name  ='Ivan' -- name of the database

declare @lastFullTime as datetime
set @lastFullorDiffTime =  '2012-09-03 19:30:00.000' -- a date and time after the last full or diff backup, remember, log backups are every 15 minutes

select 'RESTORE LOG' + @database_name FROM DISK = ''' + physical_device_name + ''' with norecovery, stats = 10'
from backupmediafamily bmf
inner join backupset as bs
on bmf.media_set_id = bs.media_set_id
where bs.type = 'L'
and bs.database_name = @database_name and bs.backup_finish_date > @lastFullorDiffTime
order by backup_finish_date


This will grab the required information from system tables containing information about the log backups and generate restore statements which, when copied, pasted and run in a new query window, will restore logs from a specific point in time.

I will grant you that more sophisticated methods exist for multiple restores (please feel free to post them here below) but when you need something which will  quickly and simply restore logs, this can be useful.