Sql-server – How to attach a SQL Server DB with a missing NDF file

sql serversql-server-2008

I had a server running that had a disk crash. The server had 2 filegroups: PRIMARY and SECONDARY. SECONDARY was stored in a different NDF file. I lost SECONDARY + the installation of the server, I have the MDF file of the PRIMARY filegroup. I also have a backup from a few months ago. Is there a way to attach the MDF file I have without the NDF I lost? I don't mind losing the tables stored on the SECONDARY filegroup.

I'm using SQL Server 2008R2 DEV. Thanks!

Best Answer

This is one way of recovering the data from your PRIMARY filegroup.

Since the database is not attached, you have to first get it upp and running, you can do that by restoring the old backup to an alternate name (Just to be sure not to owerwrite any files of importance).

Then set the database files you are missing as OFFLINE:

ALTER DATABASE <DatabaseName> 
MODIFY FILE ( NAME = <SecondaryFilegroupFileName>, OFFLINE )

Set the entire database as offline, and replace your database and transaction log files with copies from your files at the moment of the crash.

Set the database as online, and you should be able to work against all data that is not contained in the secondary filegroup to recover your data.