Tuesday, January 16, 2018

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\db\aspmantra.mdf'),
(FILENAME = 'F:\Project\db\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





No comments:

Post a Comment