Creating a new database using an MDF file

5 pts.
Tags:
Backup
Database
MDF
Restore
My database saves as MDF. I want to know what are the steps to restore or create a new database using a MDF file? I tried to restore as usual but it shows an error. Please help.

Answer Wiki

Thanks. We'll let you know when a new response is added.
An MDF file isn’t a backup file isn’t the main data file (or master data file depending on who you ask) hence the file extension MDF. You can attach the MDF to the database by right clicking on the databases folder in Enterprise Manager (SQL 2000) or Management Studio (SQL 2005) then selecting all tasks and then Attach Database.

When you do this you will get an error about the log file missing. This shouldn’t matter as SQL Server will simply create a new log file for you.

This will only work if the SQL Server was stopped when you copied the MDF file from the old SQL Server. If you copied the file while the SQL Server was running this file probably will not attach either and you will need to get a valid backup of the database.
Download help tool for sql database – SQL Server Restore Toolbox.
You can read up more on SQL Server here. 

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Denny Cherry
    Check out my SQL Server blog "SQL Server with Mr Denny" for more SQL Server information.
    66,360 pointsBadges:
    report
  • Brijesh
    Use this query :
    USE [master]
    GO
    CREATE DATABASE [database_name] ON
    ( FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Data\ .mdf' ),
    ( FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Data\ .ldf' )
    FOR ATTACH ;
    GO
    9,870 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following