Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
SQL

SQL Server: Recover Data From a Corrupted Database Using DBCC CHECKDB Before You Panic

- 31.08.26 - ErcanOPAK

🗄️ Before You Restore From Backup, Run This One Command

A query suddenly throws a corruption error – torn page, checksum mismatch – and the instinct is to panic and start restoring from last night’s backup immediately, losing a full day of transactions. There’s a faster, less destructive first step almost everyone skips.

🐞 The Problem

Msg 824, Level 24, State 2, Line 1
SQL Server detected a logical consistency-based I/O error:
incorrect checksum. Additional messages in the SQL Server error
log may provide more detail.

🔍 Why This Happens

Corruption almost always comes from the storage layer, not SQL
Server itself - a failing disk, a bad RAID controller, an
interrupted write during a power loss, or (in virtualized/cloud
environments) a storage subsystem glitch. SQL Server's page
checksums are specifically designed to CATCH this kind of damage
rather than silently return corrupted data, which is why the error
appears the moment a damaged page is read.

✅ The Fix: Diagnose the Actual Damage Before Choosing a Recovery Path

  • Run DBCC CHECKDB('YourDatabase') WITH NO_INFOMSGS, ALL_ERRORMSGS immediately — this reports exactly which objects and pages are affected, which tells you whether this is one damaged index (cheap to fix) or something systemic (needs a full restore).
  • If the damage is isolated to a NONCLUSTERED index, you can often just drop and rebuild that index — zero data loss, since the index is fully derivable from the underlying table data.
  • Only reach for DBCC CHECKDB WITH REPAIR_ALLOW_DATA_LOSS as a genuine last resort when no clean backup exists — as the name says, it can discard damaged rows to restore consistency, so a restore from a good backup is almost always safer when one is available.

🚨 What Not to Do First

  • Don’t run REPAIR commands blind, before CHECKDB has told you the actual scope — you could be discarding data unnecessarily when a much smaller fix (like an index rebuild) would have fully resolved it.
  • Don’t keep writing to the damaged database while diagnosing — further writes can spread the damage or make recovery options worse. Take a backup of the CURRENT (corrupted) state first, even if it’s just for forensics.

Corruption is a diagnosis, not a verdict — CHECKDB tells you exactly how bad it is before you commit to the most drastic recovery option available.

— Database Engineer

Related posts:

SQL Server: Fix a Filtered Index That Gets Silently Ignored Because the Query's WHERE Clause Doesn't...

SQL Server: Fix a Blocking Chain That Isn't a Deadlock and Never Resolves on Its Own

SQL Window Functions: Analytics Queries That Replace Hundreds of Lines of Code

Post Views: 4

Post navigation

Windows 11: Recover Files After Emptying the Recycle Bin by Accident
ASP.NET Core: Fix Model Binding That Silently Returns Null for a Perfectly Valid Request Body

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (952)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (837)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (624)
  • Add Constraint to SQL Table to ensure email contains @ (590)
  • Average of all values in a column that are not zero in SQL (553)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (526)
  • Find numbers with more than two decimal places in SQL (468)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps
  • Photoshop: Fix a Color Profile Mismatch That Makes Printed Output Look Nothing Like What You Saw On Screen
  • WordPress: Fix Search Results That Return Pages From a Theme You Deactivated Months Ago
  • Visual Studio: Fix a Test Project That Builds Fine Alone but Fails to Discover Any Tests After a NuGet Restore
  • ASP.NET Core: Fix a File Upload That Times Out on Slow Connections Only Because Kestrel’s Minimum Data Rate Feature Kicked In
  • JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (952)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (837)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com