Me Myself & C#

Manoj Garg’s Tech Bytes – What I learned Today

How to repair a SQL Server 2005 Suspect database

Posted by Manoj Garg on July 17, 2008

Sometimes when you connect to your database server, you may find it in suspect mode. Your database server won’t allow you to perform any operation on that database until the database is repaired.

A database can go in suspect mode for many reasons like improper shutdown of the database server, corruption of the database files etc.

To get the exact reason of a database going into suspect mode can be found using the following query,

DBCC CHECKDB (‘YourDBname’) WITH NO_INFOMSGS, ALL_ERRORMSGS

Output of the above query will give the errors in the database.

To repair the database, run the following queries in Query Analyzer,

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

and you are done. :)

lightbulbYou should keep one thing in mind while using the above queries that the repair mode used here , REPAIR_ALLOW_DATA_LOSS, is a one way operation i.e. once the database is repaired all the actions performed by these queries can’t be undone. There is no way to go back to the previous state of the database. So as a precautionary step you should take backup of your database before executing above mentioned queries.

Ha-P Querying…

37 Responses to “How to repair a SQL Server 2005 Suspect database”

  1. Deepali said

    Can ay one help me to find out reasons of database going to suspect mode,in sql server 2005.

    • bijendra rajput said

      yes i can help you.
      A database can go in suspect mode for many reasons like improper shutdown of the database server, corruption of the database files etc.

  2. Ben said

    Thanks for this one. Saved me quickly.

  3. Maurizio said

    Thank you very much for the suggested solution!! It worked great

  4. Manoj Garg said

    Glad that it helped you. :)

  5. AdoSK said

    Dakujem, dakujem, dakujem (Slovak language). International – Thank, thank, thank. I’m very happy NOW. I’m thought, that I’m in ass. Thank :)

  6. Mohit Garg said

    Great Man it worked for me as well… :)

  7. saufi said

    thanks, great code

  8. Gilberto said

    I´m brazilian, and used this code and my data base it´s alive! Thanks a lot!! Não tenho mais palavras para agradecer ao postador deste código!! Obrigado mesmo!!! Merece um grande beijo (not gay, please…:))

  9. [...] Neste site encontrei um  procedimento que funcionou perfeitamente! Lembre-se: O risco é seu ao executar o código abaixo! EXEC sp_resetstatus ‘MINHA_TABELA‘; [...]

  10. Alex said

    In this situation advise use this tool because it is very good also it has free status as far as i know-mssql repair,tool
    can help with this problem and retrieve the data, that was considered to be lost,mwill extract housekeeping data from the source database and preview the data, that can be recovered,this tool is a good solution to recover data from corrupted databases in MS SQL Server format,restore databases represent files, like any other documents, they can be easily corrupted by viruses, all sorts of malware, hard drive failures, file system errors, incorrect user actions, etc,supports both data extraction to your hard drive as scripts in SQL format and data export directly to a database in MS SQL Server format.

  11. Srgrn said

    It worked like a charm, great
    Thanks man

  12. prashanth said

    thankyou

  13. sagitariusmzi said

    This solution doesn’t worked for me,
    when i executed the above mention queries, it given me lot of errors ?

  14. Shahid Khan said

    great Code From Great Man it worked Excellent… :)

  15. Deepanshu Jouhari said

    One More Saved, Really required this information on net.

    Thanks

  16. Susannah said

    Saved my life..Thanks…I’ll be taking more regular backups from now on

  17. Munya Chaunza said

    It worked thank you.

  18. Ahsan said

    Saved my life..Thanks…

  19. David said

    Your Query is helpful but sometime when database is badly corrupted then this query is not helpful then during that time you need to use third party tool as SQL Recovery which repair and recover lost data, tables, views, stored procedures, rules, defaults, user defined data types and triggers from Microsoft SQL server database.

  20. Madhu K said

    Hi,

    Thanks for the code, it resolved my DB suspect mode issue.

  21. Rob said

    You saved the day. Thanks :)

  22. Thanks for a great piece of code, saved me an absolute ton of time

    thanks

    Allan

  23. bsking said

    It saved the day for me. thanks a ton.

  24. Antonio said

    thanks, it helped!
    just a notice for novice users: it will delete some records! in my case, i had 4 screwed invoices. after deleting them and all their records (invoice records, stock movement, equipment serial numbers, etc) in the SQL Manager, i was able to proceed with my life.

  25. M Arif Iqbal said

    Dear Friend
    Your code is very simple and very effective it help me a lot. I have resolved many suspect even damage sql server 2005 databases with it. Keep your good work going. With best wishes.
    Sometimes part of the disk is damage or it develop bad block due to this we can not backup or copy the database use http://www.anyreader.com/ to copy the data.

  26. GmE said

    Great code & effective, works fine with me.

    Thanksssssssssssss!

  27. impressive post

  28. Chris A said

    Many thanks Manoj – worked really well for me.

  29. Hey, I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say GREAT blog!…..I”ll be checking in on a regularly now….Keep up the good work! :)

  30. Hey very nice blog!!….I’m an instant fan, I have bookmarked you and I’ll be checking back on a regular….See ya

  31. Alex said

    It worked perfectly! Thanks for it!

  32. TONYE said

    Fantastic page Manoj!
    Worked first time and helped the user get productive in minutes!

  33. This saved my vSphere Virtual Center server database – thanks!

  34. Suresh said

    Cool. I tried all possible way but end up seeing something like “Your DB is in suspect mode and you can’t do this”.

    But, my DB just obeyed your code and its now recovered.

    Great! What I learned today is this!

  35. great post.. helpd a lot..

  36. Eduardo Aguirre said

    Thanks for your help

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>