SQL Server error 551, "The checksum has changed," happens when the database engine detects a corruption or inconsistency between stored checksums and the actual data. This doesn’t always mean immediate data loss, but it indicates a critical integrity violation. The simplest fix is to run the database recovery command in SQL Server Management Studio (SSMS) or the Transact-SQL (T-SQL) command line. If that fails, you’ll need to force-rebuild the corrupted file or restore from backup.
What You'll Need
- The SQL Server Management Studio (SSMS) or SQL Server Command Line (sqlcmd) tool, or direct access to the database files if restoring from backup.
- Backup of the database (critical for major fixes).
- Administrative rights to interact with SQL Server.
- For advanced cases: SQL Server 2012 or later tools (e.g., Database Engine Diagnostics for detailed corruption analysis).
Step-by-Step
- Check the exact error message in SSMS:
Open SSMS and connect to the database. Right-click the database in Object Explorer, hover over Tasks, and select Check Database Integrity. Alternatively, run this T-SQL in a new query window:
EXEC sp_checksum_repair 'database_name'Note the specific error if it mentions page, index, or data corruption. If no error appears, proceed to the next step. - Run the checksum repair command:
Execute this T-SQL to prompt SQL Server to attempt repairs:
EXEC sp_detach_db 'database_name'RESTORE DATABASE [database_name] FROM DISK = 'path\to\backup.bak' WITH REPLACE, RECOVERYThis will rebuild the database from backup, forcing checksum alignment. If the database is critical, use a full backup from before the corruption started. - If the above fails due to file corruption at the OS level, restart the SQL Server service and verify file permissions:
- Open Services (Win + R > services.msc) and stop the SQL Server service.
- In File Explorer, navigate to the SQL Server data folder (e.g., `C:\Program Files\Microsoft SQL Server\MSSQL14.SQLSERVERInst1\MSSQL\DATA`).
- Right-click the corrupted .mdf/.ldf file and repair permissions in Properties > Security. Grant the SQL Server service account read/write access.
- Restart SQL Server services and re-run the integrity check.
- If the database is read-only and won’t repair:
Forcefully detach and reattach it via command line:
DBCC CHECKDB (database_name) WITH NO_INFOMSGSIf this shows corruption, detach the database (use SSMS or `DETACH` in sqlcmd) and restore from backup with `WITH REPLACE`. - For SQL Server 2012+ with full diagnostics:
Use the built-in corruption checker:
DBCC CHECKDB (database_name) WITH ALL_ERRORMSGS, DBCC_LOGINFOIf the log shows "clustered index corruption," you may need to rebuild the index or restore the database.
Common Mistakes
- Using an incomplete or corrupted backup: Always verify the backup file integrity before restoring. Run:
RESTORE FILELISTONLY FROM DISK = 'backup.bak'first. - Ignoring file locks: SQL Server may block operations if the database is open. Detach it first in SSMS or via `DETACH` in sqlcmd.
- Skipping permissions: If the data folder lacks proper permissions, SQL Server can’t read/write files. Check the SQL Server service account’s NTFS rights.
- Overwriting an open database: Always detach before restoring (`WITH REPLACE`).
Tips
- Prevention: Enable filegroup corruption recovery in SQL Server Agent to auto-repair minor corruption. This costs disk space but catches issues early.
- For clustered indexes: Rebuild them only if the corruption is isolated to that table. Run:
ALTER INDEX ALL ON [schema].[table] REBUILD - If the database is corrupted but still accessible, consider exporting key tables via T-SQL:
SELECT * INTO new_table FROM old_table - Use SQL Server Agent jobs to regularly check for corruption via `sp_WhoIsActive` and `DBCC CHECKDB`.
Troubleshooting
If the problem persists after these steps, try these advanced options:
- Check for OS-level disk errors: Run chkdsk /f on the data drive (drive letter where SQL Server files are stored). This may require admin rights and a reboot.
- Restore from a known-good backup: If the backup file itself is corrupted, create a new one before restoring. Use the `RESTORE HEADERONLY` command to verify the backup integrity first.
- Repair the log file (if applicable): If the transaction log (.ldf) is corrupted, detach the database and restore the log file separately with `WITH REPLACE`. This is often necessary for full recovery.
- Contact Microsoft Support: If corruption is severe and cannot be resolved locally, generate a SQL Server error log (via `DBCC LOGINFO` in SSMS) and submit it to Microsoft’s Technical Support Portal.
Frequently Asked Questions
Why does SQL Server error 551 occur?
Error 551 triggers when SQL Server detects a checksum mismatch between stored metadata (e.g., index structure) and actual data on disk. Causes include: disk failures, file corruption, improper shutdowns, or permission issues.
How do I know if this is a file corruption or SQL Server bug?
Check for disk errors (run `chkdsk`) and verify file permissions. If the database is open but checksums fail, the issue is likely file-level corruption. If SQL Server itself is misbehaving, check for service crashes or logs in the SQL Server Error Log.
Can I fix this issue without restoring from backup?
Only if the corruption is minor (e.g., a single page in a table). Use `DBCC CHECKDB` with `ALL_ERRORMSGS` to identify the extent of corruption. For recoverable cases, rebuild the specific index or table with `ALTER INDEX REBUILD`. For severe corruption, a full restore is safer.
What if the database is already open and I can’t detach it?
Use the `DBCC SHRINKFILE` command to force SQL Server to rebuild the log/backup file structures, but this is risky without a backup. Always detach first.
How often should I check for this error?
For critical databases, run `DBCC CHECKDB` at least weekly or after any major operation (e.g., backups, upgrades). Monitor changes in the SQL Server error logs for unexpected corruption.
Will this error cause data loss?
Not always—SQL Server often repairs minor corruption automatically. However, severe mismatches (e.g., log file corruption) can lead to permanent data loss. Always back up before attempting repairs.