+2 votes
in Databases by (20.3k points)
I had to format my PC where I had my SQL server installed. Before formatting, I took the backup of my databases (.mdf & .ldf files). Now, I installed all the software on my machine and want to restore my databases. How can I restore the databases using the backup .mdf and .ldf files?

1 Answer

0 votes
by (48.7k points)

If you have installed MS SQL server management studio on your machine, follow the following steps to restore your databases:

1. Move your .mdf and .ldf files to the DATA folder of your SQL server.

2. Login to your SQL server from MS SQL server management studio -> Right-click "Databases” -> click “Attach”  option to open the Attach Databases dialog box.

SQL server management studio attach database

3.Click the “Add” button to open and Locate Database Files from the DATA folder of SQL server.

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