Forum Discussion

komail_2811's avatar
komail_2811
Copper Contributor
Dec 08, 2023

How To Attach MDF File Without Log File

Hi,
I have one MDF file without LDF file

when attach this file to sql i have this error , how to solve this problem ?

in first step

 

USE master 
GO 
EXEC sys.sp_attach_single_file_db @dbname = 'old_mil1', 
    @physname = N'F:\old_mil.mdf' 
GO

 

 Error : The FOR ATTACH option requires that at least the primary file be specified.

Step 2 : 

 

USE [master]
Go
CREATE DATABASE [Tester] ON
(FileName = N'F:\old_mil.mdf' )
For Attach
GO

 

Error : The FOR ATTACH option requires that at least the primary file be specified.

How to Solve This Problem , This File is Very Important for me.



  • Hello
    Please try below option

    CREATE DATABASE [Tester]ON
    (FileName = N'F:\old_mil.mdf'’)
    For ATTACH_REBUILD_LOG
    GO


    Regards
    Javier
  • olafhelper's avatar
    olafhelper
    Bronze Contributor

     


    komail_2811 wrote:

    Hi,
    I have one MDF file without LDF file

    when attach this file to sql i have this error , how to solve this problem ?

    Error : The FOR ATTACH option requires that at least the primary file be specified.


    komail_2811 , the error message is not complaining about a missing LOG file, it says the file isn't a valid primary database file.

Resources