Step 4

Create the procedure "USP_RestoreAll" by copying
and pasting the SQL code below into query analyzer. You should create this
procedure on the SQL Server where you would like to restore the full backup and
corresponding transaction log backups. If you want to restore the full backup
and corresponding transaction log backups on a different server, then copy all
the .BAK and .TRN files to that server or to a shared folder.

2.
'D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Inventory\' is the path
where all the database .BAK and .TRN files are stored.

You
can specify UNC path. Make sure SQL Server has sufficient access to the
folders.

3.
'Inventory' is the database name

4.
'D:\' is the path where you want to create the data files of the 'MyInventory'
database from the .BAK and .TRN

5.
'C:\' is the path where you want to create the log files of the 'MyInventory'
database from the .BAK and .TRN

6.
'Print' is the parameter to be passed to the procedure to generate the SQL
scripts for restoring the latest full backup and transaction log backups.
Instead of 'Print' if you pass 'Exec' as the parameter, it generates the script
and restores the .BAK and all the .TRN files.

When
you execute the above SQL statement, a SQL script is generated as shown below.
As you can see in the below script, it takes only the latest full backup and
the corresponding transaction log backups.

Conclusion

As mentioned earlier in this article, the main intent is
to show how to restore a FULL backup of a database and all corresponding
transaction log backups to the same server or to a different server, as the
same database name or as a different database name.