Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring database from .mdf and .ldf files of SQL Server 2008

For some reason I have to uninstall SQL Server 2008 R2 but before that I copied two files (.mdf and .ldf) of my database from

C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.MSSQL2008\MSSQL\DATA

Now, the question is, is it possible for me to recover the database from these files in my new installed SQL Server 2008 R2.

If yes: then how can I do this?

like image 938
Ahsan Raza Avatar asked Aug 19 '13 08:08

Ahsan Raza


People also ask

How do I import MDF and LDF files?

Run SQL Server management studio as an administrator and attach the database. Explicitly grant full control access to the MDF file and LDF file of the database. To do that, Right-click the database files Select the security tab select the appropriate user and grant full control to the user.

Can we restore database with MDF file only?

In case, if the transaction log file is missing then you can still attach MDF file in SQL Server without LDF file and if the MDF file is not accessible or corrupted then you can repair MDF file using third party SQL Recovery tools.

How do I open an MDF file in SQL Server?

Launch SSMS -> Connect to the SQL Server instance -> Right-click on Database -> Click Attach. In the new Locate Database Files window, browse the file system to locate the MDF file. Double-click it. The associated data files and log files are populated in the associated files grid view in the Attach Databases window.


1 Answers

Yes, it is possible. The steps are:

  1. First Put the .mdf and .ldf file in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ folder

  2. Then go to sql software , Right-click “Databases” and click the “Attach” option to open the Attach Databases dialog box

  3. Click the “Add” button to open and Locate Database Files From C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\folder

  4. Click the "OK" button. SQL Server Management Studio loads the database from the .MDF file.

like image 170
sridhar Avatar answered Sep 23 '22 08:09

sridhar