SQL SERVER : Create database from .MDF & .LDF file - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

SQL SERVER : Create database from .MDF & .LDF file

In this article I am going to explain how to create database from .MDF & .LDF file in Sql server.

Description & Implementation:
I have .MDF and .LDF file of database. I want to restore or create database from these files. We have 2 ways to create database from .MDF and .LDF file.

Method 1: Using  T-Sql
Run the below given query :

CREATE DATABASE aspmantra ON
(FILENAME = 'F:\Project\resthour\aspmantra.mdf'),
(FILENAME = 'F:\Project\resthour\aspmantra_log.ldf')
for attach;


Method 2: Using Sql server Management studio (SSMS)
Follow the below given steps to create database from MDF file.

Step 1: Login to Sql server database engine. Right click on database and select the Attach. See attachment

SQL SERVER : Create database from .MDF & .LDF file



Step 2: Attach database pop up window will be open. Click on add button.

SQL SERVER : Create database from .MDF & .LDF file



Step 3: Locate database files window will be open. Select the MDF file and press the Ok button.


SQL SERVER : Create database from .MDF & .LDF file




SQL SERVER : Create database from .MDF & .LDF file





What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon