An accountant called us recently with the kind of problem that keeps DBAs up at night.
Her hard drive crashed. Her SQL Server Express database was corrupted. Her last backup was from April. This was October.
Her accounting software wouldn’t start. Client financial records, transaction history, tax documents. Everything locked inside a damaged database on a dead drive.
She managed to copy the database files to a new PC before the drive completely failed. But SQL Server refused to attach them. Corruption errors appeared immediately.
No backups for six months. Her business data was trapped.
Here’s how we recovered it, what the recovery actually cost, and why this situation was completely preventable.
The Recovery Challenge
Database corruption comes in different flavors.
The severity determines whether recovery is possible.
We started by installing SQL Server 2016 to match her original version. Version compatibility matters when dealing with corrupted files. Newer versions handle database formats differently.
Attempted to attach the database through SQL Server Management Studio. The attach operation failed immediately with recovery errors. The error messages pointed to transaction log corruption.
We ran DBCC CHECKDB after attaching the database in EMERGENCY mode to allow SQL Server to access metadata. Alternatively, if attachment fails, DBCC CHECKDB can’t run directly on detached MDF/LDF files. This command scans every page in the database looking for corruption. It checks data integrity, validates indexes, and verifies internal structures.
The results showed clean data pages. No corruption in the actual table data. The transaction log was the problem.
This was the best possible outcome for a corrupted database. Data intact, log destroyed. Recovery was feasible.
Emergency Mode Access
SQL Server normally refuses to work with corrupted databases.
This protection prevents further damage. But it also locks you out of potentially recoverable data.
EMERGENCY mode lets you bypass normal recovery and open the database in a limited state. It sets the DB to READ_ONLY and SINGLE_USER, disables automatic recovery, and gives you access to read or export the data safely. You’re working without safety nets. One mistake could destroy everything.
We placed her database into EMERGENCY mode using
ALTER DATABASEcommands. This gave us read access to all tables, views, and stored procedures.
The database was accessible. Now we needed to extract everything.
Schema Extraction and Rebuild
Recovery required rebuilding the database from scratch.
We couldn’t just repair the log file, SQL Server can’t truly repair a corrupted log. The only option was to recreate a new one, but doing that usually causes some data loss. So we went with a full rebuild approach.
The first step was extracting the complete schema.
We scripted out every table definition, every view, every stored procedure, every function. The schema is your database blueprint. Miss one dependency and the rebuild fails.
Created a clean database and applied all schema scripts in the proper dependency order — base tables first, then primary and foreign keys, followed by views, functions, and stored procedures. Getting that sequence right was critical to avoid dependency errors.
Dependencies really matter. Create objects in the wrong order, and SQL Server throws errors. Get the order right, and you have an empty database ready to receive data.
Data Migration Process
Moving data from the corrupted database to the clean database required custom scripts.
Standard backup and restore wouldn’t work. The log corruption prevented normal operations.
We wrote migration scripts to copy the data table by table. The process had to handle relationships carefully.
Foreign keys enforce referential integrity. A child table can’t have records pointing to parent records that don’t exist. During migration, these constraints cause problems.
Dropped all foreign keys first. This allowed us to copy tables in any order without constraint violations. Copied every table from the EMERGENCY mode database to the clean database.
After all data was copied, we recreated the foreign keys. This re-established referential integrity in the new database.
The migration ran table by table. Hundreds of thousands of rows were moved from the corrupted database to the clean database.
Here’s a deep, in-depth guide on SQL Server migration.
Validation Was Critical
Copying data is one thing. Proving you copied everything correctly is another.
We built validation scripts to compare the two databases. First validation checked row counts. Every table in the new database had to match row counts in the original database.
The first validation run showed discrepancies. Some tables had missing rows. The migration scripts needed refinement.
We added checksum validation. This computed hash values for random samples of rows. If the data got corrupted during copy, the checksums wouldn’t match.
Refined the migration scripts based on validation failures. Ran the entire process again. The second validation showed improvement but still had gaps.
The third iteration passed completely. Every table matched. Every row accounted for. Checksums validated data integrity.
This validation process took time. But discovering missing data three months later would have been catastrophic.
Final Recovery Steps
We backed up the clean database. Tested the backup by restoring it to a different instance. The restore worked perfectly.
Copied the backup file to her new PC. Restored the database. Configured her accounting software to point to the recovered database.
The software started. All her data appeared. Transaction history loaded. Reports ran correctly.
Recovery was complete. Her business was operational again.
Facing a live outage or corruption? Start here: Emergency SQL Support.
Why She Got Lucky
This recovery succeeded because the data files survived intact. Only the transaction log was corrupted.
If the MDF file had corruption, the outcome would have been different. CHECKDB might show thousands of errors. Pages of data could be unreadable. Entire tables might be lost.
Some data corruption can be repaired. SQL Server can deallocate damaged pages and mark them as unusable. But you lose whatever data was on those pages. Partial recovery beats no recovery, but it still means data loss.
The transaction log stores changes not yet written to data files. When the log is corrupted but data files are clean, you lose recent transactions. In her case, she likely lost changes from right before the crash. Minutes of data, not months.
EMERGENCY mode only works when the data itself is readable. If pages are damaged, you’re looking at partial recovery at best. Complete loss at worst.
She got lucky. The crash hit the log, not the data.
This isn’t a rare issue; we have come across a lot of emergency situations like this that we have to act quickly on.
A Cost Analysis
Emergency recovery took six hours of specialized database work:
- Custom script development
- Multiple validation runs
- Testing and verification
Six hours of senior DBA time. That’s not cheap.
Compare this to proper backup procedures.
Her database was a few gigabytes.
DBCC CHECKDBon that size takes 30 seconds to one minute. Run it daily as part of automated maintenance.
Full database backup for a few gigabytes takes two minutes. Automated backup jobs handle this without intervention. Storage for daily backups costs almost nothing.
Differential backups every few hours add protection with minimal overhead. Transaction log backups every 15-30 minutes provide point-in-time recovery.
Total time investment for setup: one hour. Monthly oversight: 15 minutes. Storage costs: negligible for small databases.
Recovery cost: six hours of emergency DBA work, business downtime, client communication stress, and potential data loss from recent transactions.
Prevention cost: one hour setup, automated execution thereafter.
The ROI on backups is massive.
(For a real case study on backup plans that looked solid but failed during ransomware recovery, read Why SQL Server Backups Fail When You Need Them Most)
Business Impact Beyond Technical Recovery
The accountant handles client financial data. Tax records. Transaction histories. Accounts payable and receivable.
Database loss doesn’t just impact her. It impacts every client she serves.
Professional liability becomes a factor. Clients expect their financial records to be protected. Losing months of data could trigger legal issues, loss of client trust, and damage to professional reputation.
Her business depends on data integrity. A corrupted database isn’t just a technical problem. It’s an existential business threat.
Small operation doesn’t mean small risk. The data matters as much for one company as for 100 companies.
SQL Server Express is free. Backup functionality is included. The tools exist. They just need to be used.
Frequently Asked Questions
Can you always recover a corrupted SQL Server database without backups?
How long does emergency database recovery take?
What causes SQL Server transaction log corruption?
Is SQL Server Express reliable for business use?
What’s the minimum backup strategy for SQL Server?
DBCC CHECKDB daily to catch corruption early. Store backups off the primary storage device.
How much does emergency recovery cost compared to backups?
Speak with a SQL Expert
In just 30 minutes, we will show you how we can eliminate your SQL Server headaches and provide operational peace of mind