PDA

View Full Version : attach a MDF without LDF



ehsan_882000
پنج شنبه 28 مرداد 1389, 13:59 عصر
attach a MDF without LDF


Create a new database with the same name and same MDF and LDF files
Stop sql server and rename the existing MDF to a new one and copy the original MDF
to this location and delete the LDF files


Start SQL Server
Now your database will be marked suspect
Update the sysdatabases to update to Emergency mode. This will not use LOG files in start up


Sp_configure "allow updates", 1
go
Reconfigure with override
GO
Update sysdatabases set status = 32768 where name = "BadDbName"
go
Sp_configure "allow updates", 0
go
Reconfigure with override
GO


Restart sql server. now the database will be in emergency mode
Now execute the undocumented DBCC to create a log file
DBCC REBUILD_LOG(dbname,'c:\dbname.ldf') -- Undocumented step to create a new log file


(replace the dbname and log file name based on ur requirement)


Execute sp_resetstatus


Restart SQL server and see the database is online