Monday 24 May 2010

How to attach a SQL Server database (.mdf file) with a missing log (.ldf) file.

Sometimes we receive .mdf file only no log file.

If we use Attach command it gives error (something like "no log file found ")
We can attach a SQL Server database (.mdf file) with a missing log (.ldf) file.

Procedure:
Open SQL Studio
Right click on any datatbase and click "New Query"

Run the following System Stored Procedure

sp_attach_single_file_db @dbname= 'NewDatabaseName', @physname= 'C:\Users\AIqbal\Documents\Project1\northwind.mdf'

this will create new database and new log file under same folder

No comments: