I've got a database with 2 FileGroups and 3 Files. It's laid out like so: ============================================ Primary DBName_Data - EathFilename.MDF Index_Data DBName_Index - EathFilename.NDF ============================================ The Log files are: ------------------ DBName_Log.LDF EBName_Log2.LDF ============================================ We just added a new drive (raid array) to the server and I need to move the .NDF file to the new drive for performance reasons. So, my current file/paths are: EathFilename.MDF EathFilename.NDF DBName_Log.LDF EBName_Log2.LDF I need to detach the DB, and move the NDF and reattach, but I'm not sure how to do this having more than one MDF/LDF. What I want is: EathFilename.MDF GathFilename.NDF DBName_Log.LDF EBName_Log2.LDF I know to detach, all I need is: EXEC sp_detach_db 'DBName', 'true' But how do I reattach (after moving the NDF to drive G)? Thanks for any help!
sp_attach_db should allow you to specify up to 16 file names including their full path. See BOL for syntax. You can also view the following KB article on moving database files: http://support.microsoft.com/default.aspx?scid=kb;en-us;224071
I'm assuming what I need to do is: Detach the database. Copy the .NDF to drive G Reattach the database (using the .NDF on drive G Delete the old .NDF
I've been looking in BOL, and this is what I've come up w/so far. CREATE DATABASE DBName ON PRIMARY ( NAME = DBName_Data, FILENAME = 'EathDBName_Data.MDF'), FILEGROUP PRIMARY ( NAME = DBName_Index, FILENAME = 'GathDBName_Index_Data.NDF'), FILEGROUP INDEX_DATA LOG ON ( NAME = 'DBName_Log', FILENAME = 'DathDBName_log.LDF'), ( NAME = 'DBName_1_Log', FILENAME = 'EathDBName_Log2.LDF') GO Does this look correct?
In any manner .NDF doesn't deals with SP_ATTACH_DB or SP_DETACH_DB. Once you attach .MDF and .LDF you can use that .NDF by the way of ALTER DATABASE. BOL refers ALTER DATABASE Test1 ADD FILE ( NAME = Test1dat2, FILENAME = 'crogram FilesMicrosoft SQL ServerMSSQLData 1dat2.ndf', SIZE = 5MB, MAXSIZE = 100MB, FILEGROWTH = 5MB ) GO _________ Satya SKJ
Thanks for the info. I created a database on my local machine that mirrors the file structures of our production database and got it to reattach using the following code: CREATE DATABASE DBName ON PRIMARY ( NAME = DBName_Data, FILENAME = 'EathDBName_Data.MDF'), FILEGROUP INDEX_DATA ( NAME = DBName_Index, FILENAME = 'GathDBName_Index_Data.NDF') LOG ON ( NAME = 'DBName_Log', FILENAME = 'DathDBName_log.LDF'), ( NAME = 'DBName_1_Log', FILENAME = 'EathDBName_Log2') For Attach GO