Generate Restore Database Commands

Restoring a database backup from one server to another, or from one database to another on the same machine, often requires MOVE ... TO ... commands. For databases with a lot of files, this can be tedious. Use the script below to automatically generate restore database commands with correctly generated MOVE clauses for all files included in the backup.

Please, no more generating database restore statements by hand!

   “Please, no more generating database
      restore statements by hand!”

Just point the script at an existing SQL Server Backup File, and give the new database a name, along with a target folder for the data and log files, and press F5. This script is compatible with SQL Server 2005 and higher, and has been tested on a case-sensitive-collation server.

That code will generate a statement similar to this:

Have fun using this to generate restore database commands!

This post is part of our series on Database Recovery. Check out the rest of our handy SQL Server Tools!

Click here for Microsoft documentation for the RESTORE DATABASE command.