Click here to Skip to main content
15,867,141 members
Articles / Database Development / SQL Server

How to Restore SQL Server 2005 Suspect Database

Rate me:
Please Sign up or sign in to vote.
4.29/5 (64 votes)
13 Sep 2007CPOL2 min read 390.9K   46   61
How to Restore SQL Server 2005 Suspect Database

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.

SQL
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)


Written By
Program Manager
India India
Love to code

Comments and Discussions

 
QuestionIncorrect syntax near 'EMERGENCY'. Pin
Member 1595742820-Mar-23 23:42
Member 1595742820-Mar-23 23:42 
GeneralMy vote of 5 Pin
Donald Perera25-Nov-22 17:37
Donald Perera25-Nov-22 17:37 
QuestionArticle on how to restore SQL Server 2005 suspect database. Pin
Member 128364486-Nov-16 22:56
Member 128364486-Nov-16 22:56 
QuestionGreat piece of work Pin
Frankie-105898076-Jul-15 22:31
Frankie-105898076-Jul-15 22:31 
GeneralThank you so much!!! Pin
fedesanp11-Apr-14 7:41
fedesanp11-Apr-14 7:41 
QuestionRestore suspect database Pin
venkatarao sanni28-Mar-14 21:26
venkatarao sanni28-Mar-14 21:26 
QuestionThank You Pin
Member 855142811-Apr-13 21:58
Member 855142811-Apr-13 21:58 
QuestionThanks Pin
Dell.Simmons9-Apr-13 11:26
Dell.Simmons9-Apr-13 11:26 
GeneralThanks Pin
Code4Tech5-Dec-12 1:11
Code4Tech5-Dec-12 1:11 
Questionhow to secure database in client system in desktop application Pin
Member 362275216-Nov-12 3:05
Member 362275216-Nov-12 3:05 
Question5 Stars here too! Pin
bortolo5-Oct-12 11:53
bortolo5-Oct-12 11:53 
QuestionVery good! Pin
Gilberto Campos25-Sep-12 12:36
Gilberto Campos25-Sep-12 12:36 
GeneralMy vote of 5 Pin
Craig Errington20-Sep-12 5:45
Craig Errington20-Sep-12 5:45 
Questionit really works.. Pin
akshar shroff7-Jun-12 21:15
akshar shroff7-Jun-12 21:15 
GeneralMy vote of 5 Pin
ashutosh300731-May-12 22:23
ashutosh300731-May-12 22:23 
GeneralMy vote 5 stars Pin
Norbert Meier17-Apr-12 23:23
Norbert Meier17-Apr-12 23:23 
GeneralMy vote of 5 Pin
Member 868252827-Feb-12 13:36
Member 868252827-Feb-12 13:36 
GeneralMy vote of 5 Pin
nawazish12khan2-Dec-11 22:24
professionalnawazish12khan2-Dec-11 22:24 
GeneralMy vote of 5 Pin
Asrij Siraj8-Nov-11 17:48
Asrij Siraj8-Nov-11 17:48 
AnswerPerfect solution. my vote is 10 of 5 Pin
mkwiatkowski8120-Oct-11 13:32
mkwiatkowski8120-Oct-11 13:32 
GeneralMy vote of 5 Pin
Member 420927822-Sep-11 1:35
Member 420927822-Sep-11 1:35 
GeneralMy vote of 4 Pin
akhil khare15-Sep-11 21:39
akhil khare15-Sep-11 21:39 
QuestionThank you very much from Paris! It works for me ! Pin
Cybertipunch12-Jul-11 3:10
Cybertipunch12-Jul-11 3:10 
GeneralI can't even begin to thank you enough Pin
BRM_Archer29-Jun-11 11:16
BRM_Archer29-Jun-11 11:16 
GeneralMy vote of 5 Pin
y.aitelmaati1-Jun-11 23:19
y.aitelmaati1-Jun-11 23:19 

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

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