Fully automated MS SQL Restore
Posted
by hasen j
on Stack Overflow
See other posts from Stack Overflow
or by hasen j
Published on 2010-03-24T18:11:23Z
Indexed on
2010/03/24
18:13 UTC
Read the original article
Hit count: 208
I'm not very fluent with MS-SQL 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 mssql.
© Stack Overflow or respective owner