script to restore sql server transaction logs

use master
go

declare @databaseName varchar(50), @backupFileName varchar(100), @restoreDirectory varchar(100)

— Set the name of the database to restore
set @databaseName = ‘database’
— Set the path to the directory containing the database backup
set @restoreDirectory = ‘pathBackupsLogsfolder’

— Create the backup file name based on the restore directory, the database name and today’s date
set @backupFileName = @restoreDirectory + @databaseName + ‘_’ + replace(convert(varchar, getdate(), 112), ‘-‘, ‘.’) +’1330’+ ‘.trn’

RESTORE LOG database FROM DISK = @backupFileName WITH NORECOVERY

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.