Database can be created using MDF file using below statement-
In this example LiveTest is DB for which only MDF is available and LDF file is lost. Login to SQL Management Studio, open query window and execute the below statement after replacing the DB name and MDF path-
USE master;
GO
CREATE DATABASE LiveTest
ON (FILENAME = ‘S:\TestData\LiveTest.mdf’)
FOR ATTACH;
GO
Following message will be displayed after the execution of the statement-
File activation failure. The physical file name “T:\LFVLog\LiveFloorView.ldf” may be incorrect. New log file ‘T:\SDSLog\LiveFloorView_log.LDF’ was created.
This statement tried to create log file for this DB. It is created in default transaction log directory set in SQL Database Properties …>Database settings….> Log field.
In case you want to change the MDF and LDF file path then:
Select the DB in left panel, Right Click DB—>Task—>Bring Task Offline.Copy the Transaction Log and Data file into correct Drive,
Make sure to change the Data file path and Transaction log path in the SQL Database Properties …>Database settings….> Log and Data field.
Then Bring the DB Online.