SQL

SQL - Repair a Suspect Database

Overview

Problem / Symptoms:

SQL Server database corruption can be a problem and can cause serious damage to a database

Common causes are sudden server restarts/outages where a clean shutdown wasn't performed resulting in Smartcontroller not being able to open the Database once the system has restarted.

Diagnosis:

Generally, when entering into SSMS you will notice a (Suspect) tagged next to the database name. 

Solution / resolution:

  • EXEC sp_resetstatus [YourDatabase];

  • ALTER DATABASE  [YourDatabase]  SET EMERGENCY

  • ALTER DATABASE  [YourDatabase]  SET SINGLE_USER  WITH ROLLBACK  IMMEDIATE

  • DBCC checkdb([YourDatabase])

Once completed at the very end of the query window will tell you the minimum DBCCCHECK to perform. Generally, you will have two options dependant on the level of corruption.

​​​​​​​

  • DBCC CheckDB ([YourDatabase], REPAIR_REBUILD) - No Data loss

  • DBCC CheckDB ([YourDatabase], REPAIR_ALLOW_DATA_LOSS) - Data loss is required to repair db

  • ALTER DATABASE  [YourDatabase]  SET MULTI_USER