"how to restore to a different database in sql server?" Code Answer


you can create a new db then use the "restore wizard" enabling the overwrite option or:

view the contents of the backup file:

restore filelistonly from disk='c:your.bak'

note the logical names of the .mdf & .ldf from the results, then:

restore database mytempcopy from disk='c:your.bak'
   move 'logicalnameforthemdf' to 'c:mytempcopy.mdf',
   move 'logicalnamefortheldf' to 'c:mytempcopy_log.ldf'

this will create the database mytempcopy with the contents of your.bak.

(don't create the mytempcopy, it's created during the restore)

example (restores a backup of a db called 'creditline' to 'mytempcopy'):

restore filelistonly from disk='e:mssqlbackupcreditline.bak'


restore database mytempcopy from disk='e:mssqlbackupcreditline.bak'
   move 'creditline' to 'e:mssqlmytempcopy.mdf',
   move 'creditline_log' to 'e:mssqlmytempcopy_log.ldf'

>restore database successfully processed 186 pages in 0.010 seconds (144.970 mb/sec).
By David John on August 14 2022

Answers related to “how to restore to a different database in sql server?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.