How to Repair a Suspect Database in SQL Server?
Resolved Email & Outlook
MS
Michael Scofield
March 5, 2019
8 replies
11,870 views
Reviewed by moderators
3 participants

Power cut mid-write and now our production database shows SUSPECT in SSMS. Last full backup is 5 days old and losing those days would be very bad. What is the safe order of operations here?

SQL Server 2016, database is about 200GB.

Accepted answer
Marked as the solution to this question

Do not detach the database and do not restart the service repeatedly. Order of operations:

Emergency plus CHECKDB fixed it with zero rows lost. Recovery tool stays bookmarked for the next power cut. Solved.

What does REPAIR_ALLOW_DATA_LOSS really delete? I want to know before I use it.

REPAIR_ALLOW_DATA_LOSS fixes the structure and not your data. The repair deallocates damaged pages, so the rows on those pages are gone, and it does not keep foreign key relationships in line. Microsoft treats it as the last resort.

Use this order:

1. Copy the MDF and LDF files to a safe drive first.
2. Restore the last full backup and the log backups to a test server. This is the safest fix.
3. If no backup works, set the database to EMERGENCY and SINGLE_USER, then execute DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS.
4. Execute DBCC CHECKDB again, check the application data and take a new full backup.

Can I still take a log backup from a suspect database?

Sometimes. In EMERGENCY mode you can try BACKUP LOG ... WITH NO_TRUNCATE to save the tail of the log. That gives you a restore path up to the point of the failure, which beats a repair that deletes pages. Keep every backup file, because you need them if the repair goes wrong.

Tail log backup saved the last hours. Thanks.