Database recovery can be achieved by using a new name, which often meets the needs of the business. When you use a different name to restore the database, you will have to set up a new location for each file in the database. If you have not previously known what files are in the database, you can run the RESTORE FILELISTONLY declaration to obtain the number and name of the database files. Running restore FILELISTONLY can provide you with information about the file, such as the logical name of the file, the physical name, whether the file is a data file or a log file.
Next, execute the RESTORE database declaration, including a new name for the database, and a backup of the files that will be stored. If you want to process log files, use NORECOVERY.
In the following example, we will create a database called Mynwind2_test, which is a copy of MyNwind2, MyNwind2 file contains two files Mynwind2_data and Mynwind2_log. As MyNwind2 already exists, Mynwind2_data and Mynwind2_log will be transferred to another place.
Use master
Go
You can now determine the number and name of files in a file backup.
RESTORE filelistonly
From MyNwind2
Finally, you can restore the MyNwind2 file to the Mynwind2_test file
RESTORE DATABASE Mynwind2_test
From MyNwind2
With RECOVERY,
Move ' mynwind2_data ' to ' D:\MyData\MyNwind2_Test_data.mdf ',
Move ' mynwind2_log ' to ' D:\MyData\MyNwind2_Test_log.ldf '
Go