
Introduction
A DBA receives an alert:
“DBCC CHECKDB found consistency errors in database ‘SalesDB’.”
This is one of those messages that can immediately raise concern in a production environment.
The first reaction might be:
“Let’s run DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS.”
Stop.
Database corruption requires a controlled investigation. Repairing the database without understanding the problem can potentially result in data loss.
The correct approach is:
Detect → Understand → Protect → Find the Cause → Recover → Validate
This article explains how to approach SQL Server database integrity issues safely.
Before You Start
This article primarily applies to SQL Server 2019, SQL Server 2022 and later versions, including SQL Server 2025.
The same general principles apply to Azure SQL Managed Instance, while Azure SQL Database has some differences in administration and platform architecture.
Before taking any corrective action, collect:
- SQL Server version and edition
- Database name
- Database recovery model
DBCC CHECKDBoutput- SQL Server error log messages
- Windows/System event information
- Storage/I/O information
- Last known good full backup
- Differential and log backup availability
- Recent hardware, storage, driver or firmware changes
- Any recent SQL Server upgrade or patch
Required Permissions
Running DBCC CHECKDB requires appropriate database permissions. On SQL Server, Microsoft documents sysadmin, db_owner, or db_ddladmin as permissions that can be used to execute DBCC CHECKDB; permissions can also be granted more narrowly depending on the environment and requirements. (Microsoft Learn)
Repair operations require greater care and are subject to additional restrictions, including SINGLE_USER mode for the REPAIR_* options. (Microsoft Learn)
Production Tip: If you can investigate the problem but don’t have permission to perform the repair or restore, involve the DBA/database recovery team. Don’t request sysadmin simply because you need to execute one troubleshooting command.
What Does Database Integrity Mean?
SQL Server database integrity has both physical and logical aspects.
DBCC CHECKDB checks the physical and logical consistency of the database, including database pages, rows, allocation structures, relationships between indexes and tables, system tables and other database structures. (Microsoft Learn)
A database integrity problem can therefore mean much more than:
“One table is corrupted.”
The problem could involve:
- Data pages
- Index pages
- Allocation structures
- Metadata
- System tables
- Database files
- Logical relationships
- Certain specialized objects
Why Does Database Corruption Happen?
Database corruption can have several possible causes.
1. Storage or hardware problems
Examples include:
- Failing disks
- SAN/storage problems
- Storage controller issues
- Faulty write caching
- Firmware problems
- I/O path failures
Microsoft specifically recommends investigating the complete I/O path when consistency errors occur, including storage, drivers, firmware, BIOS, storage networking and memory. (Microsoft Learn)
2. Memory problems
Bad or unstable memory can potentially contribute to corruption.
This is one reason database corruption should not automatically be treated as a SQL Server software problem.
3. Driver or firmware issues
Storage drivers, firmware and other components in the I/O path can contribute to problems.
If corruption repeatedly appears and disappears, Microsoft notes that disk-cache or I/O-path issues should be investigated. (Microsoft Learn)
4. SQL Server or operating-system issues
SQL Server and Windows updates can contain fixes for known issues.
This doesn’t mean:
“SQL Server caused the corruption.”
It means the SQL Server version and applicable updates should be part of the investigation.
Microsoft recommends checking for relevant SQL Server cumulative updates/service packs and known fixes when investigating consistency errors. (Microsoft Learn)
5. Previous improper recovery or storage incidents
A database that has previously experienced an abnormal shutdown, storage failure or other serious infrastructure incident may require additional investigation.
6. Backup or restore problems
A backup is only useful if it is valid and recoverable.
This is why restore testing is such an important part of a database recovery strategy.
Step 1: Don’t Panic. Confirm the Problem
If someone reports:
“The database is corrupted.”
Don’t accept that statement without evidence.
Start with:
DBCC CHECKDB ('SalesDB') WITH NO_INFOMSGS;
For an initial investigation, you should normally run DBCC CHECKDB without a repair option.
The objective at this stage is to understand what SQL Server is reporting.
For example:
CHECKDB found 0 allocation errors
and 5 consistency errors
in database 'SalesDB'.
Save the complete output.
Don’t just copy the final summary.
The individual error messages often contain important information about the affected object, page or structure.
Step 2: Understand What CHECKDB Found
DBCC CHECKDB may report different types of problems.
For example:
Allocation errors
Consistency errors
Index errors
Metadata errors
Page errors
Don’t immediately assume that every error requires the same solution.
The exact error messages matter.
You may also use:
DBCC CHECKTABLE ('dbo.Orders') WITH NO_INFOMSGS;
if CHECKDB identifies a particular table.
DBCC CHECKTABLE checks the integrity of the specified table and its associated indexes. (Microsoft Learn)
Step 3: Check the SQL Server Error Log
Don’t investigate CHECKDB output in isolation.
Review the SQL Server error log around the time the problem was first detected.
Look for evidence of:
- I/O errors
- 823 errors
- 824 errors
- 825 errors
- Checksum failures
- Read/write failures
- Storage-related errors
For example, repeated I/O errors should immediately make you suspicious of the underlying storage environment.
The objective is to answer:
Is this an isolated database problem, or is there an infrastructure problem still occurring?
Step 4: Check Windows and Storage Events
If corruption is suspected, involve the infrastructure/storage team early.
Check:
- Windows System event log
- Storage alerts
- SAN/NAS alerts
- Disk health
- RAID status
- Storage controller events
- Firmware
- Drivers
- Hardware diagnostics
Microsoft recommends resolving underlying hardware-related problems before restoring or repairing the database. (Microsoft Learn)
This is extremely important.
Imagine this situation:
Storage problem
↓
Database corruption
↓
Restore database
↓
Storage problem remains
↓
Database becomes corrupted again
You haven’t solved the problem.
You’ve only restored the database temporarily.
Step 5: Check Your Backups Before Doing Anything Destructive
This is one of the most important steps.
Ask:
Do we have a known-good backup?
Check:
- Last successful full backup
- Differential backups
- Transaction-log backups
- Backup chain
- Backup location
- Backup accessibility
- Backup integrity
- Restore test results
If you have a known-good backup, restoring it is normally preferable to attempting a repair when permanent consistency errors exist. Microsoft explicitly recommends restoring from a known-good backup as the primary recovery method. (Microsoft Learn)
Step 6: Determine the Recovery Point
Suppose:
Full Backup
Sunday 01:00
Differential
Wednesday 01:00
Log backups
Every 15 minutes
And corruption was discovered Thursday at 10:30.
You need to determine:
When did the corruption actually occur?
This can be difficult.
Finding when corruption was detected isn’t necessarily the same as finding when it occurred.
That distinction matters when selecting a recovery point.
Step 7: Restore the Database to Another Server
If possible, don’t experiment with the production database first.
Restore the suspected backup to another SQL Server environment.
For example:
Production
↓
Known-good backup
↓
Test/Recovery Server
↓
DBCC CHECKDB
↓
Validate database
Then run:
DBCC CHECKDB ('SalesDB') WITH NO_INFOMSGS;
If the restored backup passes integrity checks, you have valuable evidence that the backup is usable.
You can then plan the production recovery properly.
Step 8: Don’t Immediately Run REPAIR_ALLOW_DATA_LOSS
This deserves its own section because it is one of the most common mistakes.
You may see:
REPAIR_ALLOW_DATA_LOSS
in the CHECKDB output.
That does not mean:
“Run this now.”
Microsoft explicitly states that REPAIR_ALLOW_DATA_LOSS is not an alternative to restoring from a known-good backup and should be considered an emergency last resort when restoration isn’t possible. (Microsoft Learn)
Why?
Because repair can involve deallocating rows or pages to remove inconsistencies.
That can mean:
The database becomes physically consistent, but some data may be lost.
And physical consistency does not automatically mean logical/business consistency.
REPAIR_REBUILD vs REPAIR_ALLOW_DATA_LOSS
| Option | Purpose | Data Loss Risk |
|---|---|---|
REPAIR_REBUILD | Repairs certain errors without data loss | No intended data loss |
REPAIR_ALLOW_DATA_LOSS | Attempts to repair broader consistency problems | Yes |
| Restore backup | Recover from known-good database state | Depends on recovery point/data changes |
REPAIR_FAST exists for backward compatibility and doesn’t perform repair actions. (Microsoft Learn)
The important point is:
A repair option is a recovery decision, not simply a troubleshooting command.
Step 9: If Repair Is the Only Option
Sometimes there is no usable backup.
That is when the situation becomes significantly more difficult.
If repair is being considered:
- Stop and document the current state.
- Resolve underlying hardware/storage problems first.
- Preserve copies of the database files as appropriate.
- Capture the complete
CHECKDBoutput. - Determine the minimum repair level recommended by
CHECKDB. - Understand the potential data-loss implications.
- Obtain appropriate approval for the production recovery decision.
- Run the repair carefully.
- Run
CHECKDBagain. - Validate the data and business logic afterward.
Microsoft specifically recommends creating physical copies of the database files before REPAIR_ALLOW_DATA_LOSS and considering extraction of as much information as possible before repair. (Microsoft Learn)
Step 10: Validate After Repair
This is where many troubleshooting guides stop too early.
Suppose:
DBCC CHECKDB
↓
0 errors
Can you now say:
“Everything is fixed”?
No.
A successful repair can leave the database physically consistent while logical or business-level inconsistencies remain.
Microsoft recommends manual validation after repair and specifically recommends DBCC CHECKCONSTRAINTS to identify potential constraint-related inconsistencies. (Microsoft Learn)
Run:
DBCC CHECKCONSTRAINTS ('SalesDB');
Then validate important business data.
For example:
Customer count
Order count
Financial totals
Recent transactions
Critical tables
Foreign-key relationships
Application functionality
The database being online is not the same as the application data being correct.
Step 11: Take a New Backup After Recovery
After a successful repair or recovery, create an appropriate backup.
Microsoft recommends backing up the database after repairs are completed. (Microsoft Learn)
But don’t forget:
Fix the underlying cause before declaring the incident closed.
If the storage problem is still present, another corruption event may occur.
A Real-World Troubleshooting Approach
When I investigate a database integrity issue, I prefer to think about it in this order:
CHECKDB reports errors
↓
Confirm & capture complete output
↓
Check SQL Server error log
↓
Check Windows / storage events
↓
Investigate hardware / I/O path
↓
Check known-good backups
↓
Can we restore?
↙ ↘
YES NO
↓ ↓
Restore Evaluate
backup repair
↓ ↓
CHECKDB Controlled
↓ repair
Validate ↓
↓ CHECKDB
Production ↓
Recovery Validate
Common Mistakes to Avoid
Running REPAIR_ALLOW_DATA_LOSS immediately
This can turn a corruption problem into a data-loss problem.
Ignoring the storage team
If hardware or I/O is causing corruption, SQL Server repair alone won’t solve the underlying problem.
Assuming CHECKDB errors always mean SQL Server is at fault
Corruption can have hardware, storage, driver, firmware, memory and other causes. (Microsoft Learn)
Checking only whether the database is ONLINE
A database can be online while still requiring logical/business validation after recovery.
Not testing backups
A backup that cannot be restored isn’t much help during a production emergency.
Fixing the database but not the root cause
If the underlying I/O problem remains, corruption may return.
Quick Database Integrity Troubleshooting Checklist
Run DBCC CHECKDB without repair options
Save the complete output
Identify affected database objects
Review SQL Server error logs
Check Windows event logs
Investigate storage/I/O problems
Check hardware, drivers and firmware
Check SQL Server version and applicable updates
Identify the last known-good backup
Verify the backup chain
Test restore to another server where possible
Prefer restore over repair when a good backup exists
Treat REPAIR_ALLOW_DATA_LOSS as a last resort
Preserve database files before destructive repair
Run CHECKDB again after recovery/repair
Run DBCC CHECKCONSTRAINTS where appropriate
Validate critical business data
Take a new backup
Fix the underlying infrastructure problem
Document the incident and recovery steps
The Golden Rule of Database Corruption
If there is one thing I would want a new DBA to remember, it is this:
Never treat
REPAIR_ALLOW_DATA_LOSSas the first solution to a database integrity problem.
The safer mindset is:
Investigate first. Protect the evidence. Fix the underlying problem. Restore from a known-good backup whenever possible. Repair only when necessary. Validate everything afterward.
A database being ONLINE doesn’t necessarily mean the recovery is complete.
And a database passing CHECKDB after a repair doesn’t automatically prove that every business transaction is correct.
That is why database integrity troubleshooting should always involve both technical validation and business validation.
Production Tip
When a production database reports corruption, don’t ask only:
“How do I repair the database?”
Ask:
“Why did this happen, do I have a clean recovery path, and how do I make sure it doesn’t happen again?”
That question will usually lead you toward the right solution.
Microsoft’s recommended hierarchy is important here: investigate and resolve the underlying cause, restore from a known-good backup when possible, and use DBCC CHECKDB repair options only when restoration isn’t possible. (Microsoft Learn)
Discover more from Technology with Vivek Johari
Subscribe to get the latest posts sent to your email.


