MsSQLWindows Server

MSSQL: Restore db from MDF and LDF

This guide will show you how to restore db from MDF and LDF. Typically this situation when a shared windows customer (exa id) asking for db backup certain day. But in our MSSQL01 server does not has .bak file. Only rubbish file called MDF and LDF is available. How to do it?

You can place them in the appropriate folder containing the other SQL databases on the server. In General setting this folder will be
c:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA
but it depends on your SQL Server Setup time; data directory path may be in a different location.
Follow these steps:
Step 1: Open your Microsoft SQL Server and right click on Database and Click on Attach, as shown in below screen.
Step 2: It will open the below dialog, for adding a file click on ‘Add’ Button
Step 3: Locate your .MDF file from your Drive.
Step 4: It will display Data file (EMP.mdf) and Log file (EMP.ldf) shown as per below screen.
Click on Ok.
Step 5:

That’s it; it will create a database with data, you can check your MS SQL Object Explorer -> database and it will show the database attached.

Leave a Reply

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