For this example, we will assume the database name is "TEST" with the files test.mdf and test.ldf.
When we try to attach the mdf, we get an error message saying the file is corrupted.
- Rename the TEST.mdf, and TEST.ldf to TEST_OLD.mdf and TEST_OLD.ldf
- Create TEST as a database so that it generates a blank mdf and ldf
- Stop SQL server service
- Delete the blank test.mdf and test.ldf, and rename the test_old.mdf and test_old.ldf to test.mdf and test.ldf to force sql to read the corrupted files
- Start SQL server service
- The database will show that it is in "suspect" mode
- Run this script taken from
http://www.codeproject.com/Articles/20333/How-to-Restore-SQL-Server-2005-Suspect-Database EXEC sp_resetstatus 'yourDBname'; ALTER DATABASE yourDBname SET EMERGENCY DBCC checkdb('yourDBname') ALTER DATABASE yourDBname SET SINGLE_USER WITH ROLLBACK IMMEDIATE DBCC CheckDB ('yourDBname', REPAIR_ALLOW_DATA_LOSS) ALTER DATABASE yourDBname SET MULTI_USER
- This will most likely cause a fair amount of data loss, but the database will be accessible
For non technical user, it is not an easy task to repair sql database mannually, i would recommend to such people, go for third party application, which is easy and fast way to recover sql database. Go to Google search there lot of tools available there, one such application is here:
ReplyDeletehttp://www.recoverydeletedfiles.com/sql-database-recovery-software.html