Tuesday, May 26, 2015

Attach DB without log file(.ldf) in SQL Server

The following article is to create the Database into SQL Server instance without .ldf file. 
There are 2 files required to create database in SQL Server instance


1 .mdf is the primary database file where all table ,view,indexes , SP etc.. stored.
2 .ldf is the transaction log file where all transaction logs are stored since last backup.

we may end up situation where we have only .mdf file to attach. in this case we can create .ldf when we creating the primary database file (.mdf) into the database.

the following query will create the .mdf file and create .ldf file in the database.


CREATE DATABASE <DB Name>
ON (FILENAME = 'Physical path of .mdf file')
FOR ATTACH_REBUILD_LOG  

I hope this article will be very helpful to all. Thanks for reading this article.

“Keep reading and share the knowledge”  
“Grow more trees to save the Earth”

No comments:

Post a Comment