Click here to Skip to main content
Licence CPOL
First Posted 3 Sep 2007
Views 182,644
Bookmarked 44 times

How to Restore SQL Server 2005 Suspect Database

By | 13 Sep 2007 | Article
How to Restore SQL Server 2005 Suspect Database
 
Part of The SQL Zone sponsored by
See Also

Introduction

If your project's database is in suspect mode, then no transaction will take place until and unless you repair your database. That causes a show stopper for your up and running application. Here, you will find a way to get out of this.

Background

Your Database is in Suspect Mode. I guess, you haven't experienced this problem till now. But, if it comes to you and if the database is LIVE, then it's time to read this article to get out of this tension.

Using the Code

If you find your database in Suspect mode, then please keep your nerve strong. Just proceed step by step what I am written below. I think you will get out of this trouble. SQL Server 2005 introduced a new DB Status called Emergency. This mode can change the DB from Suspect mode to Emergency mode, so that you can retrieve the data in read only mode. The steps are... After executing the script given below, you will get back your database in operational mode. Actually I have tried with two of my existing live systems and found no data loss.

Note: Obviously there are two more options available. Run REPAIR_ALLOW_DATA_LOSS to ensure the database is returned to a structurally and transitionally consistent state. Here are a few things to bear in mind about emergency mode repair: it's a one-way operation. Anything it does cannot be rolled back or undone. If this worries you (if someone ever got into that state, then surely don't have the healthy concern about data that they should have in the first place) then make a copy of the damaged database before you run emergency mode repair.
As it's a one-way operation, you cannot wrap it in an explicit user-transaction.
It's the only repair option available in emergency mode - if you try to use REPAIR_REBUILD, then it won't work.

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

Points of Interest

You will be happy that your database as well as the application are still in workable condition. :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Suvendu Banik

Program Manager

India India

Member

Love to code

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote 5 stars PinmemberNorbert Meier23:23 17 Apr '12  
GeneralMy vote of 5 PinmemberMember 868252813:36 27 Feb '12  
GeneralMy vote of 5 Pinmembernawazish12khan22:24 2 Dec '11  
GeneralMy vote of 5 Pinmemberasrij17:48 8 Nov '11  
AnswerPerfect solution. my vote is 10 of 5 Pinmembermkwiatkowski8113:32 20 Oct '11  
GeneralMy vote of 5 PinmemberMember 42092781:35 22 Sep '11  
GeneralMy vote of 4 Pinmemberakhil khare21:39 15 Sep '11  
QuestionThank you very much from Paris! It works for me ! PinmemberCybertipunch3:10 12 Jul '11  
GeneralI can't even begin to thank you enough PinmemberBRM_Archer11:16 29 Jun '11  
GeneralMy vote of 5 PinmemberTheChange23:19 1 Jun '11  
GeneralThanks!!! PinmemberLuis Alonso Ramos14:04 13 Apr '11  
GeneralMy vote of 5 Pinmemberthirinwe19:00 30 Mar '11  
Generalits working Pinmemberyvarjun20:20 21 Nov '10  
GeneralThanks this workrd for me PinmemberVuyiswa Maseko22:24 24 Mar '10  
GeneralThis worked like a charm. PinmemberMember 42593219:35 5 Dec '09  
Generalbacking up a database in spsupect status PinmemberLido Taha22:47 14 Oct '09  
Generalit restores the database but there is loss of data PLEASE HELP Pinmembertheodoraaaa5:11 28 Sep '09  
GeneralIt worked for me Pinmembermercyjms0:29 24 Sep '09  
GeneralThank you so much. Good work !!! Pinmembertomket_668:43 6 Sep '09  
GeneralThanks man it worked Pinmemberashishshevale23:46 30 Aug '09  
QuestionThis doesn't work on system databases Pinmembersrulyt1:55 22 Jun '09  
AnswerThanks to author Pinmemberchatakan23:44 6 Jul '09  
GeneralSaved me too. PinmemberShai Bar-Lev22:15 29 Apr '09  
GeneralWorked for me. Pinmemberteza5914:08 18 Feb '09  
GeneralTHANKS!!!! Pinmemberadmlange23:16 17 Feb '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120528.1 | Last Updated 14 Sep 2007
Article Copyright 2007 by Suvendu Banik
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid