Bobcares

Restore database from .mdf and .ldf files

by | Oct 7, 2021

Wondering how to restore database from .mdf files? We can help you.

For small or large-scale organizations, SQL Server is the best and successful RDBMS with highly integrated services to manipulate the SQL database over the Server.

As part of our Server Management Services, we assist our customers with several database queries.

Today, we will discuss how to restore LDF and MDF files to a database.

 

Restore database from .mdf files

First of all, let us see a few prerequisites our Support Techs recommend.

  1. We need to detach the database. Otherwise, if we try to attach a database that does not detach we will get an error.
  2. Then we need to maintain MDF File and LDF file in a specific folder before going to attach.
  3. In addition, we have to locate MDF Files and LDF Files in the same location.

 

  • Through SQL Server Management Studio

1. Initially, we open the MSSQL Studio and click on the ‘databases’ dropdown

2. We will get a list of databases, from which we select the database to restore.

3. Then we right-click on the database >> Tasks >> Detach.

4. Now we need to find the location to put the .mdf and .ldf files.

5. Right-click on the database >> Tasks >> restore.

6. Then, in the new window, we click on the files option.

7. The location shown in the ‘Restore as’ column is where the .mdf and .ldf files are stored.

8. Eventually, we go to that location and delete the current .mdf and .ldf files for the database.

9. After that, we put the new files in the location.

10. Now to attach the new files to the database, from MSSQL Studio >> Right click on ‘Databases’ drop out on the top >> Attach.

11. Then in the new window, we click on Add >> Select the corresponding .mdf file.

12. Finally, we click on OK.

  • Using T-SQL

Initially, we login to the SQL Server database engine.

Then we go to New Query Window and use Create Database with Attach close:

CREATE DATABASE MyDatabase 
ON (FILENAME = 'C:\SQLServer\MyDatabase_Data.mdf'), 
(FILENAME = 'C:\SQLServer\ MyDatabase _Log.ldf') 
FOR ATTACH;

[Need further assistance? We are here for you]

 

Conclusion

In short, we saw how our Support Techs restore databases from .mdf files.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.