SQLTeam.com | Weblogs | Forums

Import SQL MDF file


#1

I have .mdf file from the old server to the SQL Server 2008 RTM which is already dead.) OS stopped working and wont boot / repair at all. Now I am trying this .mdf file to attach to my new SQL server 2012 SP 3. But I can't do anything because it is corrupt. What I need to do with this file to repair my database?


#2

A backup would be helpful ...

Using MDF you need to use a single-file attach (assuming you do not ALSO have the NDF file)

If the SQL Service was running when the system failed then the data in the MDF may be incomplete (which is where the NDF file would help as that would have the log of transactions and could (Hopefully!) rollback any that has not been committed.

Does the MDF attach? If not what error do you get? If it attaches how are you determining that it is corrupt? Have you run DBCC CHECKDB? and if so what errors did you get?


#3

Ok, if you find that your .mdf file is corrupted. So, if you have any recent healthy backup of the database file. then You may create a new database on newer version with the same database file name and restore the recent healthy backup to the same.
AND No recent healthy backup available then you may try to REPAIR_ALLOW_DATA_LOSS option with DBCC CHECKDB which may repair corruption. But this is not recommended as while repairing it delete the records and data loss will occur.
Last and best option is to use MS SQL Server Recovery Tool which comes with best features and that not only repairs the corrupt .mdf file but also gives you many other feature to manage database files. Take a test of its free demo version.


#4

A RESTORE from backup file would be the best option ... anything else is most probably going to lead to data loss.


#5

You must also check this. The other suggestion was when backup is not available.


#6

Sorry, you are quite right. Didn't read that way to me as I read it, but that is indeed what you have written :slight_smile: