If you use the Restore option in SSMS and
- The database has more than one data file
(e.g. MyStuff.mdf, MyStuff1.ndf, MyStuff2.ndf etc)
- The default location for the SQL server differs from that of the source server (e.g. C: instead of D
then the GUI / Wizard will change the destination for each file to the destination server’s default folder.
If you try to run the restore then you will see the following error
File 'C:\testmssql\data\Sales\MyStuff.mdf' is claimed by ‘MyStuff_0'(3) and ‘MyStuff_DAT'(1). The WITH MOVE clause can be used to relocate one or more files.
Msg 3176, Level 16, State 1, Line 1
If you generate the SQL code from the Restore dialog box, then you will see that it will use the WITH MOVE option correctly, however it will use the same destination file name for each data file.
RESTORE DATABASE [assystv5_FR]
DISK = N'C:\testmssql\backup\MyStuff_DB.BAK'
FILE = 1,
My question : is there an easy way around this, other than generating the TSQL code and modifying the file names manually?
(I’m writing a user guide for doing simple SQL 2005 tasks and it would be good to have a method of doing this that didn’t involve the user having to determine the correct file names, generating the TSQL code and then manually modifying them).