DBCC CHECKDB with MSSQL
- Microsoft provide DBCC CHECKDB to check the integrity of all objects in a database.
- DBCC CHECKDB checks for:
- Service broker message types
- Service broker service contracts
- Service broker services
- Service broker service queues
- Service broker conversation endpoints
- Service broker conversation groups
- Service broker remote service bindings
- Allocation of all data pages for all tables including system tables
- Allocation of all index pages for all tables including system tables
- Allocation of all index pages for all indexed views
- Allocation of text
- Allocation of image objects
- Structural integrity of all tables
- Structural integrity of all indexes
Applies to:
- Microsoft SQL Server 2000
- Microsoft SQL Server 2005
- Microsoft SQL Server 2008
DBCC CHECKDB DOs
- Run DBCC CHECKDB after hours, it's very resource intensive.
- DBCC CHECKDB repairs can only work if the database is in single user mode: see: How to drop recalcitrant databases in MSSQL
- if DBCC CHECKDB find errors, first run:
DBCC CHECKDB ( 'sql911',REPAIR_FAST);
go
DBCC CHECKDB ( 'sql911',REPAIR_REBUILD);
go
go
DBCC CHECKDB ( 'sql911',REPAIR_REBUILD);
go
- If you still have errors, run:
BEGIN TRANSACTION trans-DBCC
DBCC CHECKDB ( 'sql911',repair_allow_data_loss);
go
DBCC CHECKDB ( 'sql911',repair_allow_data_loss);
go
- The begin transaction will allow you to rollback the transaction if the data loss is not acceptable.
- Don't forget to commit or rollback the transaction.
DBCC CHECKDB DON'Ts
- DBCC CHECKDB already runs:
- DBCC CHECKALLOC for every object in the database
- DBCC CHECKTABLE for every table in the database
- you do not run DBCC CHECKALLOC or DBCC CHECKTABLE afterward.
- Do NOT run DBCC CHECKDB willy-nilly, it's very resource intensive.
- DBCC CHECKDB uses tempdb to do the sorting.
- DBCC CHECKDB blocks log truncations until it has finished reading the logs.

