MDF files contain your SQL Server database table information. These files are used to archive backups of the database in case a hard drive crash occurs or data corruption leaves the database unusable. The MDF file is converted to SQL using the "sp_attach_single_file_db" stored procedure. This procedure is included with all versions of the SQL Server engine. Executing this stored procedure converts the tables contained in the MDF file to an SQL database, which is then used to query table information.
Step 1
Click your Windows "Start" button and select "All Programs." Click the "SQL Server" program group. Click "SQL Server Management Studio" from the menu list. This opens the SQL manager console where you attach your MDF file.
Video of the Day
Step 2
Click the SQL Server name on the left side of the screen. This is where your MDF file restores and attaches. Click the "New Query" button to open a command prompt.
Step 3
Enter the following code into your SQL command console:
sp_attach_single_file_db 'new_db_name', 'mdf_file_location'
Replace "new_db_name" with the name of the new SQL database. Replace "mdf_file_location" with the physical location of the MDF file. This is the full physical path such as "C:\directory\mdf_file.MDF."
Step 4
Press the "F5" key to execute your database statement. The MDF file is retrieved, converted and attached to the SQL Server.
Video of the Day