To restore a database on SQL Server using .mdf, .ldf, or .ndf files, rather than performing a restore, you will actually need to attach the database. There are two ways to do this.
Using Enterprise Manager
To attach a database using Enterprise Manager, follow these instructions:
- Expand the registered SQL server
- Right-click Databases, select All Tasks -> Attach Database…
- Click the “…” button to browse for the .mdf file
- Highlight the necessary .mdf file and click OK
- Click OK again
The database will now show up in Enterprise Manager
Using Query Analyzer
To attach a database for use in Transact-SQL, you’ll need to use the MSSQL Query Analyzer tool. If you’ve never used the Query Analyzer tool, you can follow these steps:
- First, you’ll need to navigate to the Query Analyzer by going to the Start menu -> All programs -> Microsoft SQL Server -> Query Analyzer
- In the dialogue box marked “Connect to SQL Server” enter the name of your SQL Server as well as your Login name and Password
- Click the OK button
- This will open an empty window where you can now enter your queries
The following is a series of sample commands based on your files above. You will need to specify the correct directory where these files exist (this example has the files in the C:\SQL directory).
EXEC sp_attach_db @dbname = N’rs_ds’,
@filename1 = N’C:\SQL\rs_ds_dat1.mdf’,
@filename2 = N’C:\SQL\rs_ds_dat3.ndf’,
@filename3 = N’C:\SQL\rs_ds_dat4.ndf’,
@filename4 = N’C:\SQL\rs_ds_dat2.ldf’
And there you have it! Using either of these methods, you now have the ability to restore a database on SQL Server.