Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recover MDF File

Status
Not open for further replies.

forecasting

Programmer
May 2, 2002
130
0
0
Is it possible to recover a database from its mdf/ldf files? My OS was corrupted and I had to reinstall SQL Server on my work machine. I have the .mdf files but no .bak.
 
In "most" cases YES ...

If you have both the MDF and LDF the command you would run in Query Analyzer(QA) would be ...

(NOTE: "MyDB" and "MyDir" are for example only ... you need to substitute these values for the names of your real DBs as well as the path they reside in)

EXEC sp_attach_db @dbname = N'MyDB',
@filename1 = N'c:\MyDir\MyDB_Data.mdf',
@filename2 = N'c:\MyDir\MyDB_log.ldf'

If you have an issue with this command failing and returning an error about the associated Log File(LDF), rename the log file(LDF) to something diffrent and then execute the following command in QA ...

EXEC sp_attach_single_file_db @dbname = 'MyDB',
@physname = 'c:\MyDir\MyDB.mdf'

It will probably return a message saying that this will create a new log file ... which is exactly what we want to do!

As a side note ... you really posted this question in the wrong forum. It should have been posted in the SQL Server Setup and Administration forum. There is also a MS SQL Server Programming forum too. Just a friendly FYI.

Please let us know the outcome of your situation.



Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top