Click here to Skip to main content
15,886,362 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 392K   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

 
GeneralMy vote of 5 Pin
y.aitelmaati1-Jun-11 23:19
y.aitelmaati1-Jun-11 23:19 
GeneralThanks!!! Pin
Luis Alonso Ramos13-Apr-11 14:04
Luis Alonso Ramos13-Apr-11 14:04 
GeneralMy vote of 5 Pin
thirinwe30-Mar-11 19:00
thirinwe30-Mar-11 19:00 
Generalits working Pin
yvarjun21-Nov-10 20:20
yvarjun21-Nov-10 20:20 
GeneralThanks this workrd for me Pin
Vimalsoft(Pty) Ltd24-Mar-10 22:24
professionalVimalsoft(Pty) Ltd24-Mar-10 22:24 
GeneralThis worked like a charm. Pin
Member 42593215-Dec-09 9:35
Member 42593215-Dec-09 9:35 
Generalbacking up a database in spsupect status Pin
Lido Taha14-Oct-09 22:47
Lido Taha14-Oct-09 22:47 
Generalit restores the database but there is loss of data PLEASE HELP Pin
theodoraaaa28-Sep-09 5:11
theodoraaaa28-Sep-09 5:11 
it restores the database but there is loss of data PLEASE HELP
GeneralIt worked for me Pin
mercyjms24-Sep-09 0:29
mercyjms24-Sep-09 0:29 
GeneralThank you so much. Good work !!! Pin
tomket_666-Sep-09 8:43
tomket_666-Sep-09 8:43 
GeneralThanks man it worked Pin
ashishshevale30-Aug-09 23:46
ashishshevale30-Aug-09 23:46 
QuestionThis doesn't work on system databases Pin
srulyt22-Jun-09 1:55
srulyt22-Jun-09 1:55 
AnswerThanks to author Pin
chatakan6-Jul-09 23:44
chatakan6-Jul-09 23:44 
GeneralSaved me too. Pin
Shai Bar-Lev29-Apr-09 22:15
Shai Bar-Lev29-Apr-09 22:15 
GeneralWorked for me. Pin
teza5918-Feb-09 14:08
teza5918-Feb-09 14:08 
GeneralTHANKS!!!! Pin
admlange17-Feb-09 23:16
admlange17-Feb-09 23:16 
GeneralThank-you very much! Pin
MarkCorsi9-Jan-09 5:38
MarkCorsi9-Jan-09 5:38 
GeneralThanks, I owe you one big time! Pin
srulyt16-Nov-08 22:50
srulyt16-Nov-08 22:50 
QuestionDatabase Suspect Error Pin
sujithkumarsl9-Nov-08 23:00
sujithkumarsl9-Nov-08 23:00 
GeneralThank you!!! Pin
Luis C. Lopez3-Nov-08 7:50
Luis C. Lopez3-Nov-08 7:50 
GeneralYou are a god amongst children Pin
Kosher18-Sep-08 15:16
Kosher18-Sep-08 15:16 
GeneralFixed my problem Pin
eNocNRoll17-Jun-08 8:01
eNocNRoll17-Jun-08 8:01 
GeneralRe: Fixed my problem Pin
Suvendu Banik22-Jun-08 23:58
Suvendu Banik22-Jun-08 23:58 
GeneralAnother success story! Pin
Kent Rothrock15-Jun-08 6:43
Kent Rothrock15-Jun-08 6:43 
Generalrestore suspect database in SQL-2000 Pin
sqlbie2-Jun-08 6:38
sqlbie2-Jun-08 6:38 

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.