SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Restoring db with multiple ndf''s using SSMS Express


Restoring db with multiple ndf''s using SSMS Express

Author
Message
Ian-386680
Ian-386680
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 6

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]

FROM

DISK = N'C:\testmssql\backup\MyStuff_DB.BAK'

WITH

FILE = 1,

MOVE N'MyStuff_DAT'

TO N'C:\testmssql\data\Sales\MyStuff.mdf',

MOVE N'MyStuff_0'

TO N'C:\testmssql\data\Sales\MyStuff.mdf',

etc…

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).


Ian-386680
Ian-386680
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 6

I've found the cause of the problem.

All of our data files had the file extension '.mdf' (don't blame me, I didn't create the database) Presumably SSMS looks at the extension, assumes (not unreasonably) that there should only be one mdf file and so uses the name of the first mdf file it comes across.


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search