Attaching an SQL Server Database without LOG file

Sometimes due to some hassle or if you are in hurry, you may download a database (.mdf file) directly from somewhere. But, when you try and attach this database in your SQL Server Management Studio you are not able to attach it. This is due to absence of LOG (.ldf) file. But there is a possible workaround for this. You can create or generate a LOG file by executing following query in SQL Server. Here it is:

CREATE DATABASE AdventureWorks2012

ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL12.JEKISHANMSSQL\MSSQL\DATA\AdventureWorksDW2012_Data.mdf')

Here, I have written the query to recreate a LOG file for AdventureWorksDW2012_Data.mdf file that I had downloaded from codeplex.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s