Click here to Skip to main content
Licence CPOL
First Posted 3 Sep 2007
Views 183,504
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
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  
GeneralThank-you very much! PinmemberMarkCorsi5:38 9 Jan '09  
Although we have not done an exhaustive test yet for data loss, your solution got us back up and running again! This was a highly transactional database and would have been a nightmare to reconstruct. (I got caught sleeping at the wheel without appropriate backups... Wink | ;-) ) The database runs a piece of software and the tech guys and dba's at the software company had all but given up helping me resolve the issue. I tried your solution as a last ditch effort before I went home and hung myself.
 
Thanks again. Great article - huge help!
GeneralThanks, I owe you one big time! Pinmembersrulyt22:50 16 Nov '08  
QuestionDatabase Suspect Error Pinmembersujithkumarsl23:00 9 Nov '08  
GeneralThank you!!! PinmemberLuis C. Lopez7:50 3 Nov '08  
GeneralYou are a god amongst children PinmemberKosher15:16 18 Sep '08  
GeneralFixed my problem PinmembereNocNRoll8:01 17 Jun '08  
GeneralRe: Fixed my problem PinmemberSuvendu Banik23:58 22 Jun '08  
GeneralAnother success story! PinmemberKent Rothrock6:43 15 Jun '08  
Generalrestore suspect database in SQL-2000 Pinmembersqlbie6:38 2 Jun '08  
GeneralRe: restore suspect database in SQL-2000 PinmemberSuvendu Banik17:53 2 Jun '08  
GeneralIt worked for me. PinmemberKenThompson4:16 20 May '08  
GeneralRe: It worked for me. PinmemberSuvendu Banik17:55 2 Jun '08  
GeneralRe: It worked for me. PinmemberJoginipalli Vamshi Krishna21:11 13 Jun '11  
QuestionWhy? Pinmemberdragoshilbert21:18 17 Sep '07  
AnswerRe: Why? PinmemberMember 353052519:17 12 Apr '08  
GeneralREPAIR_ALLOW_DATA_LOSS option Pinmemberchopeen1:33 13 Sep '07  
GeneralRe: REPAIR_ALLOW_DATA_LOSS option PinmemberSuvendu Banik3:36 13 Sep '07  
GeneralRe: REPAIR_ALLOW_DATA_LOSS option Pinmemberchopeen3:52 13 Sep '07  
AnswerRe: REPAIR_ALLOW_DATA_LOSS option PinmemberSuvendu Banik18:12 13 Sep '07  

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
Web02 | 2.5.120529.1 | Last Updated 14 Sep 2007
Article Copyright 2007 by Suvendu Banik
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid