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.
- We need to detach the database. Otherwise, if we try to attach a database that does not detach we will get an error.
- Then we need to maintain MDF File and LDF file in a specific folder before going to attach.
- 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.
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]
In short, we saw how our Support Techs restore databases from .mdf files.