So when I try this code (one line at a time):
BACKUP DATABASE [test] TO DISK = N'C:\test\test.bak' WITH INIT , NOUNLOAD , NAME = N'Test backup', NOSKIP , STATS = 10, NOFORMAT
RESTORE DATABASE [test2] FROM DISK = N'C:\test\test.bak' WITH FILE = 1, MOVE N'test_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\test2.MDF', MOVE N'test_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\test2_log.LDF', NOUNLOAD, REPLACE, STATS = 10
The first line works, the .bak file is created and the query is successful. Then I try the second line above, and I get this error:
Msg 3234, Level 16, State 2, Line 1
Logical file 'test_Data' is not part of database 'test2'. Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
The code that I’m trying came from here.
Any idea what I’m doing wrong?
‘Test_Data’ is most likely not the name of the logical file that contains the data in the database that has been backed up. Use
RESTORE FILELISTONLYas suggested to determine the name of this file – or right-click on the database from which the backup was taken and look at the properties – where you can view the names of the file(s) associated with the database.If ‘Test_Data’ is the correct logical file name then most likely you have more than one backup stored in the one .bak file. Try restoring through SSMS rather than T-SQL to get a better feel for what you’re dealing with – you can always script out the restore, rather than running it, to see how it should’ve been scripted.