Perform Maximum Recovery after SQL Database Corruption
Summary: This blog talks about the possible solutions to perform maximum recovery of data after SQL database corruption. You can try to restore the database from backup or run DBCC CHECKDB command with repair options to fix database corruption. If nothing works, using a SQL recovery tool can help.
Contents
The Job role and responsibility of DBA is demanding and Challenging; he has to look after day to day critical performance of Database and, when it comes to performance issue then, it is the responsibility of the DBA to perform maximum recovery after SQL database corruption.
There are several reasons that can cause database corruption. “Osiris” for example is a Ransomware, used to attack systems including databases. It is hard to prevent all the possible attacks by hackers or/and viruses. Hardware failure is another reason for database corruption, and when business day to day transaction is totally dependent on your database then, it could hamper the complete business.
What needs to be done in such a cryptic situation?
My advice is to face the problem and try the following possible solutions:
Fix 1: Verify if you have a backup available
If you have a backup available, you can use it to restore the database. The problem with the backup is that you may lose some data according to the backup date. If the last backup was made 3 days ago, you would lose the data of the last 3 days. It is possible to recover data in a specific hour if you take a transaction log backup. However, if your database is corrupt, it will not be possible. That is why it is necessary to program regular backups. You can use a combination of transaction log backups, full backups and differential backups if necessary.
Try to test if your backup works. You have an option “Verify only “ to verify if the backup is working fine.
RESTORE VERIFYONLY FROM DISK = C:\AdventureWorks.BAK
GO
Backup is your preparation against data loss, and it should be protected and taken at the highest priority, Every DBA is aware of some prerequisite while dealing with database backup plan. Keeping Backup at a different location is good practice also, in many cases we have experienced that virus attack on database and backup as well. So we have to be extra cautious in such scenarios.
Fix 2: Repair a database using inbuilt options
If you do not have a current database backup or if your backup is damaged, the second alternative would be to repair the database. Restoring the database may take longer if your database has several TB in size or it will perform fast if it is just a database with few MB.
You can use the DBCC command in SSMS or any other SQL Server tool of your preference. This command will show you the error messages. If your database is big, you can use the TABLOCK option or NO_INFOMSGS to run the command faster. However, the access to the database will be slower because a lock will be produced by the command.
If you suspect that just some database is corrupt, you can use the DBCC CHECKTABLE to repair specific tables.
DBCC CHECKDB command uses a lot of space in the TEMPDB database, so it is advisable to use the option ESTIMATEONLY to estimate the space required on the TEMPDB especially when the database is big.
DBCC can be used to repair your database using different options. One of the options is REPAIR_BUILD and, if it gets fail then, you can use the REPAIR_ALLOW_DATA_LOSS option, that will repair but lose some data if necessary.
DBCC CHECKDB ('databasename', REPAIR_ALLOW_DATA_LOSS)
Fix 3: Repair SQL database using SQL recovery tool
If you do not have a backup or the DBCC CHECKDB cannot repair your database, you can use the Stellar Repair for MS SQL. This software will repair the corrupt SQL database.
The software recommends stopping the SQL Server service and copies the database to a different location.
You will need to know the location of your MDF file to repair. The Find button allows searching for the MDF file.
Once the data file is selected, you need to press the Repair button to start the repairing process. This software repairs the complete database and provides the facility to save in four different formats.
Video Guide: How to Use Stellar Repair for MS SQL
Conclusion
Repairing a Database is always a challenging task for any DBA, But it can be possible if we can more explore in this concern area. In this article, we show different options to restore or repair a database in cases of disasters. We mentioned the backup and restored strategy as the first option, use the DBCC commands as a second option and finally we have mentioned the Stellar Repair for MS SQL. This software can easily repair your database in an intuitive way and to which you can rely on!!
Due to virus attack, our organization SQL database 2016 got corrupted. I want to repair corrupted database and recover all data.
Is DBCC CHECKDB repair option ensure complete recovery?
In critical scenario, DBCC CHECKDB command does not repair corrupt data. So, I’ll recommend to try trusted third party tool Stellar Repair for MS SQL.
Read below blog post to know more about DBCC CHECKDB repair options:
Read More
Yesterday, I downloaded software from the Internet and installed on my system. Due to software virus problem occur in my system. To sort out this issue I scan my pc from Antivirus but when I access SQL 2010 database. It shows the database corruption issue. So, to get rid of this situation I used DBCC CHECKDB command but still facing the same issue. Please suggest any other method which fixes this issue.
Mostly time we are facing power outage problem which seemed to cause an issue with our database. When we are trying to access our database it looks like the database is corrupted.
Please suggest the best solution to recover the database.
Hi Team,
My SQL database file got corrupted and I do not have back up of the database.
Can you please help me to recover the database from a corrupted .mdf file?
Check out the useful reference for repairing MDF file: Read More
My organization using SQL ENVIRONMENT from last 10 years. In which all data of organization & customers are stored.
Yesterday, our database crashed without any error message. We have a backup copy but it was updated 17 days ago.
I have tried some paid tools but no one delivers promising output.
HELP!
Try free demo of Stellar Repair for MS SQL for analysis. I hope that it will fulfill your need.
Is it possible to diagnose the root causes responsible for damage to SQL database file?
Right now, you should focus on recovery of lost database files. Sometimes, unknown errors are responsible for damage to SQL database.