Saturday, August 17, 2013

SQL Server - Restore the database using mdf

Today I had to restore the database from MDF file and the log file associated with this database was not available. MDF file is the place where all the data get stored and the log files stores log information which helps in restoring to the previous working condition in case of failure.


it is very easy to attach the database using SSMS.

Right click on the Databases folder and select Attach


Fig 0.1

















which will open up the below window


Fig 0.2



















Click on add and browse the MDF file from the stored path


Fig 0.3

















Though the log file is not available, still the reference to the file exist in the MDF and hence we need to remove the log file path information from here before proceeding.
Fig 0.4


So we can either take the back up of the database for future use or copy MDF and LDF files or only MDF files.