Link to home
Start Free TrialLog in
Avatar of DotNetThinker
DotNetThinkerFlag for United States of America

asked on

Restore DB from MDF without LDF

I have SQL Server 2005, yesterday our data was corrupted and we need to know if/how we can recover from an MDF without the LDF. I've found a couple solutions when I searched but they all seem to be for SQL Server 2000. Any help is greatly appreciated.
Avatar of Aneesh
Aneesh
Flag of Canada image

sp_attach_single_file_db [ @dbname = ] 'dbname'
, [ @physname = ] 'physical_name'
Not reliably, no.

You can try this:

EXEC sp_attach_single_file_db @dbname = 'dbname',
@physname = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\dbname.mdf'

But its certainly not guaranteed to work.
ASKER CERTIFIED SOLUTION
Avatar of twoboats
twoboats

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of twoboats
twoboats

sp_attach_single_file_db will only work if the file was detached cleanly
CREATE DATABASE NewDB
      ON (NAME = 'NewDB_data', FILENAME = 'c:\temp\newdb.MDF')
      FOR ATTACH_REBUILD_LOG

will respond with error about ldf not existing, but will still create:

File activation failure. The physical file name "c:\temp\newdb_log.ldf" may be incorrect.
New log file 'c:\temp\newdb_log.LDF' was created.
Avatar of DotNetThinker

ASKER

sp_attach_single_file_db doesn't look like an option b/c the mdf was still attached when we our hard drive was corrupted.
thanks twoboats. That is very similar to the solutions I've found for SQL Server 2000.
You're welcome.

Yes, it's a modification of same, just with a way round not being able to update systables directly.
When I run this line:

ALTER DATABASE <your db> SET EMERGENCY

I get an error:

...The PageAudit property is incorrect.