How to Convert an MDF to SQL

Written by jim campbell
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Convert an MDF to SQL
Attach an MDF to the database server. (data security image by dinostock from Fotolia.com)

An MDF file contains all SQL Server database tables and stored procedures. The MDF file is used as a backup to archive the data saved to the database. To "convert" the MDF file back to SQL, attach it to your SQL Server database. This can be done with or without the LDF file, which is a log file that keeps the transactions executed on the database. Converting the MDF to SQL is called "attaching," and it activates the database on your server.

Skill level:
Moderately Challenging

Other People Are Reading

Instructions

  1. 1

    Click the SQL Server Windows "Start" button. Select "All Programs," and choose "SQL Server" from the Programs list. In your SQL Server directory, click "SQL Server Management Studio." This opens the main SQL Server console.

  2. 2

    Click your database server name on the left side of the window. If you only have one SQL Server installed on the network, only one icon is displayed. Click your server name, then click "New Query" to open the command line.

  3. 3

    Enter the following code into the console command line window:

    sp_attach_single_file_db 'db_name', 'mdf'

    Replace "db_name" with the name you want displayed on the SQL Server. The "mdf" string is the physical location of the MDF file on the hard drive.

  4. 4

    Press the "F5" key to execute the database stored procedure and attach the MDF file the SQL Server. It may take several minutes if the MDF file is several gigabytes. The console returns a "Success" message when it is finished attaching the database file to your server.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.