Sometimes we have to face a critical situation when SQL Server database going to Suspect Mode. In that moment no work can be done on database. Database may go into suspect mode because the primary file group is damaged and the database cannot be recovered during the startup of the SQL Server
Reason for database to go into suspect mode:
- Data files or log files are corrupt.
- Database server was shut down improperly
- Lack of Disk Space
- SQL cannot complete a rollback or roll forward operation.
How to recover database from suspect mode:
Step 1: Change the status of your database. Suppose database name is “BluechipDB”
EXEC sp_resetstatus '';
EXEC sp_resetstatus 'BlueChipDB'
Step 2: Set the database in “Emergency” mode
ALTER DATABASE SET EMERGENCY;
ALTER DATABASE BlueChipDB SET EMERGENCY
Step 3: Check the database for any inconsistency
Step 4: If you get any error after executing DBCC CHECKDB then immediately bring the database in SINGLE USER MODE by running following query. If no error found then you need not execute the following query.
ALTER DATABASE SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE BlueChipDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Step 5: For safety, take the backup of the database.
Step 6: Run the following query as next step. Remember while using the below query, that uses REPAIR_ALLOW_DATA_LOSS, is a one way operation that is 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 in step 5 mentioned above.
DBCC CHECKDB ('', REPAIR_ALLOW_DATA_LOSS);
DBCC CheckDB ('BlueChipDB', REPAIR_ALLOW_DATA_LOSS)
Step 7: Finally, bring the database in MULTI USER mode
ALTER DATABASE SET MULTI_USER; ALTER DATABASE [BlueChipDB] SET MULTI_USER
Step 8: Refresh your database server and verify the connectivity of your database. Now users should be able to connect to the database properly. If any data loss, you can restore database – backup taken in step 5.