Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>FROM a post at SQL Server Forums <a href="http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=85187" rel="nofollow noreferrer">Attaching MDF without LDF</a>:</p> <p>If you want to attach a MDF without LDF you can follow the steps below It is tested and working fine</p> <ol> <li><p>Create a new database with the same name and same MDF and LDF files </p></li> <li><p>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.</p></li> <li><p>Start SQL Server</p></li> <li><p>Now your database will be marked suspect 5. Update the sysdatabases to update to Emergency mode. This will not use LOG files in start up</p></li> </ol> <blockquote> <pre><code>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 </code></pre> </blockquote> <ol start="6"> <li><p>Restart sql server. now the database will be in emergency mode</p></li> <li><p>Now execute the undocumented DBCC to create a log file</p></li> </ol> <blockquote> <p>DBCC REBUILD_LOG(dbname,'c:\dbname.ldf') -- Undocumented step to create a new log file.</p> </blockquote> <p>(replace the dbname and log file name based on ur requirement)</p> <ol start="8"> <li><p>Execute sp_resetstatus </p></li> <li><p>Restart SQL server and see the database is online.</p></li> </ol> <p><strong>UPDATE:</strong> DBCC REBUILD_LOG does not existing SQL2005 and above. This should work:</p> <pre><code>USE [master] GO CREATE DATABASE [Test] ON (FILENAME = N'C:\MSSQL\Data\Test.mdf') FOR ATTACH_REBUILD_LOG GO </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload