Fully automated SQL Server Restore
- by hasen j
I'm not very fluent with SQL Server commands.
I need a script to restore a database from a .bak file and move the logical_data and logical_log files to a specific path.
I can do:
restore filelistonly from disk='D:\backups\my_backup.bak'
This will give me a result set with a column LogicalName, next I need to use the logical names from the result set in the restore command:
restore database my_db_name from disk='d:\backups\my_backups.bak' with file=1,
move 'logical_data_file' to 'd:\data\mydb.mdf',
move 'logical_log_file' to 'd:\data\mylog.ldf'
How do I capture the logical names from the first result set into variables that can be supplied to the "move" command?
I think the solution might be trivial, but I'm pretty new to SQL Server.