Attaching a database with out log file…
This is a simple trick which should not be used unless you have no other option to recover the log file. Suppose you need to attach a database and can not find the associate log files, you can still attach the database and bring it online with rebuilding the log files.
Follow below syntax for performing this operation:
USE [master]
GO
CREATE DATABASE [Database] ON
( FILENAME = N'[Datafile1 Complete Path]' )
FOR ATTACH_REBUILD_LOG
GO
Alternately if you prefer using GUI to attach a database, simply remove the log file while attaching the database. SQL Server will rebuild the log file in that case. However please be advised that if your database was not cleanly shutdown before detachment, then attempting to rebuild log file will not bring the database online.
Comments