DBCC checkdb / dbcc checktable

  • 65
  • 0
  • 2022-09-21

DBCC checkdb / dbcc checktable

1. Review the suspect_pages table in msdb to check if other pages are encountering this problem.

      Select * from  msdb..suspect_pages 

2. follow the steps blow to fix data corruption for each database, 

    1) backup database before actions

     2)  find damaged objects, 

USE master
DBCC CHECKDB (DBName) WITH ALL_ERRORMSGS, NO_INFOMSGS, TABLERESULTS;

     3) repair the damaged objects for each DB

    USE master
    ALTER DATABASE DBName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

    Use  DBName;
    DBCC CHECKTABLE (TableName, repair_rebuild);
    DBCC CHECKTABLE (TableName, REPAIR_ALLOW_DATA_LOSS); --if repair_rebuild not work  

     USE master
     DBCC CHECKDB (MSDB, REPAIR_ALLOW_DATA_LOSS);

    USE master
    ALTER DATABASE DBName SET MULTI_USER;

    4)  backup database after repair

3.  check SQL error log , database properties : recovery model / compatibility level …….