Monday, September 24, 2012

How to convert a .mdf file into a new SQL DB in MS SQL

Open your new query window in MS SQL server Management studio.

Paste this and press F5


Instructions
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.

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.

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."

4.Press the "F5" key to execute your database statement. The MDF file is retrieved, converted and attached to the SQL Server.


sp_attach_single_file_db
'AspnetDB', 'C:\Study\mvc\App_Data\DB.mdf'

No comments:

Post a Comment