posted 9/29/2010 by sqlscottgleason - Views: [2184]
This collection of notes/scripts orginally came from SQLTeam (http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=85187)
EXEC sp_attach_single_file_db @dbname = 'DBNAME', @physname = 'location\DBNAME.mdf'OR
1. Create a new database with the same name and same MDF and LDF files
2. 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.
3. Start SQL Server
4. 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
Sp_configure "allow updates", 1goReconfigure with overrideGOUpdate sysdatabases set status = 32768 where name = "BadDbName"goSp_configure "allow updates", 0goReconfigure with overrideGO
6. Restart sql server. now the database will be in emergency mode
7. 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)
8. Execute sp_resetstatus <dbname>
9. Restart SQL server and see the database is online.
Cool. Good information for us inferior developers.
I don't even want to tell you why I have to use this process (on a monthly basis)<sigh>
But, I'm glad you found the info usefull. :-)
I had this question in my mind for quite sometime. Thanks for providing a step by step soultion for this.