Troubleshooting Guide: SQL Server Error 5228 — “Table Error: Object ID %d”
Why This Error Happens
Error 5228 occurs when SQL Server’s consistency checker (DBCC CHECKDB/CHECKTABLE) detects structural corruption in a table’s data or index pages, typically caused by underlying disk I/O failures, faulty storage hardware, or improper shutdowns. This can also result from corrupted page headers, mismatched row offsets, or bit-level corruption introduced by antivirus software scanning database files. In rare cases, it stems from bugs in storage drivers or filesystem-level corruption on Windows Server 2025 when using ReFS or NTFS volumes with misconfigured caching policies.
Step-by-Step Resolution Guide
Step 1: Identify the Scope of Corruption
- Run
DBCC CHECKDB (YourDatabaseName) WITH NO_INFOMSGS, ALL_ERRORMSGS;in SQL Server Management Studio (SSMS) to confirm the full extent of damage. - Note the specific Object ID and Index ID referenced in the error message for targeted repair.
- Check the SQL Server error log (default path:
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) for correlating I/O or disk warnings.
Step 2: Restore From a Clean Backup (Preferred Method)
- Verify your most recent full backup predates the corruption event using
RESTORE HEADERONLY FROM DISK = 'C:\Backups\YourDB.bak';. - Perform a restore sequence: full backup, followed by differential and transaction log backups, using
WITH NORECOVERYuntil the final log restore. - Validate backup integrity using
RESTORE VERIFYONLY FROM DISK = 'C:\Backups\YourDB.bak';before committing to this as your recovery path.
Step 3: Run Targeted Repair if No Clean Backup Exists
- Set the database to single-user mode:
ALTER DATABASE YourDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;. - Execute
DBCC CHECKTABLE ('YourTableName', REPAIR_ALLOW_DATA_LOSS);only as a last resort, since this may permanently delete corrupted rows. - Revert the database back to multi-user mode:
ALTER DATABASE YourDatabaseName SET MULTI_USER;.
Step 4: Investigate Hardware and Storage Health
- Open Windows Server 2025 Event Viewer and check the System log under
Windows Logs > Systemfor Disk, NTFS, or Storport errors around the time of corruption. - Run
chkdsk C: /f /r(adjust drive letter accordingly) during a scheduled maintenance window to repair filesystem-level issues. - Confirm your SAN/RAID controller firmware and drivers are updated to the latest vendor-supported version.
Step 5: Exclude SQL Server Files From Antivirus Scanning
- Navigate to your antivirus console and add exclusions for
.mdf,.ldf, and.ndffile extensions. - Exclude the SQL Server data directory, typically located at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\. - Restart the SQL Server service via
services.mscto ensure the exclusion takes effect cleanly.
Alternative or Verification Steps
- Re-run
DBCC CHECKDB (YourDatabaseName) WITH NO_INFOMSGS, ALL_ERRORMSGS;after remediation — a clean result with zero allocation or consistency errors confirms the fix. - If corruption recurs frequently, consider migrating the database files to a different physical storage volume and enable Page Verify CHECKSUM (
ALTER DATABASE YourDatabaseName SET PAGE_VERIFY CHECKSUM;) to catch future I/O corruption early.