Sql – Attaching an MDF file without LDF file

sqlsql serversql-server-2008sql-server-2008-r2

Does anyone know if there is a way to attach just a SQL Server MDF file (without .LDF) file.
The log file for database got deleted and I have tried to attach the MDF, it does not work.
I have tried running the script to attach file but did not help:

USE master;
GO
EXEC sp_attach_single_file_db @dbname = 'AdventureWorks2012', 
    @physname = 
N'C:\ProgramData\Homefront\Database\DB1.mdf';

Please helpp !!!!

Best Answer

Also try these methods...

CREATE DATABASE AdventureWorks2012 
ON (FILENAME = N'C:\ProgramData\Homefront\Database\DB1.mdf')
FOR ATTACH_REBUILD_LOG
GO

OR Try this...

CREATE DATABASE AdventureWorks2012 
ON  ON (FILENAME = N'C:\ProgramData\Homefront\Database\DB1.mdf')
FOR ATTACH
GO
Related Topic