Search

Monday, December 12, 2011

Repair a Suspect database

Today when I connect to the Database Server, I saw Database is in Suspect Mode. So, Server is not allowing me to do anything on the Database. A database can go into 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 (‘DBName’) WITH NO_INFOMSGS, ALL_ERRORMSGS
The above query will give the exact status of the Database. Now, To repair the database, I ran the following queries,
EXEC sp_resetstatus ‘DBName’;
ALTER DATABASE DBName SET EMERGENCY
DBCC checkdb(‘DBName’)
ALTER DATABASE DBName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB (‘DBName’, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE DBName SET MULTI_USER
and now I can access my Database.
One thing we should keep 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 reverted. There is no way to go back to the previous state of the database. So as a precautionary step we should take backup of our database before executing above mentioned queries.

No comments:

Post a Comment