How to Repair Database if DBCC CHECKDB doesn’t Work?

Summary: When your SQL database encounters consistency errors or gets corrupt, you can use the DBCC CHECKDB command and get to know the details of the issue(s) with the database. DBCC CHECKDB command checks the SQL database for physical and logical consistency issues. It checks the consistency of database pages, rows, allocation pages, index relationships, system table referential integrity, etc. This guide details the process of utilizing the DBCC CHECKDB command to rectify errors in the SQL database. Additionally, we will explore an advanced MS SQL repair software as an alternative solution when the standard DBCC CHECKDB proves ineffective in repairing the database.

Stellar Download

 

Given below is the syntax of the command:

DBCC CHECKDB (Affected_DB) WITH NO_INFOMSGS, ALL_ERRORMSGS

This command tells you about the minimum level of repair you need to apply to fix the database.

For example, the output of the command could be something similar to the one given below:

CHECKDB found 0 allocation errors and 10 consistency errors in database Affected_DB’. Repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKDB (Affected_DB)

Repairing Database by Using DBCC CHECKDB Repair Levels

SQL Server offers three repair levels — REPAIR_FAST, REPAIR_REBUILD, and REPAIR_ALLOW_DATA_LOSS. Based on the DBCC CHECKDB recommendation of the required repair level, you can execute the DBCC CHECKDB command for repairing the database.

Syntax of DBCC CHECKDB with repair options is as follows:

DBCC CHECKDB
[ ( database_name | database_id | 0
[ , NOINDEX
| , { REPAIR_ALLOW_DATA_LOSS | REPAIR_FAST | REPAIR_REBUILD } ]
) ]
[ WITH
{
[ ALL_ERRORMSGS ]
[ , EXTENDED_LOGICAL_CHECKS ]
[ , NO_INFOMSGS ]
[ , TABLOCK ]
[ , ESTIMATEONLY ]
[ , { PHYSICAL_ONLY | DATA_PURITY } ]
[ , MAXDOP = number_of_processors ]
}
]
]

Why DBCC CHECKDB for Repairing May Not Have Worked?

If DBCC CHECKDB didn’t work, it means you have used the REPAIR_FAST repair option as it doesn’t perform any repair actions. REPAIR_FAST option is meant only for providing backward compatibility while you try to repair the database with other repair options.

You may also not be able to repair the database by using REPAIR_REBUILD if the database has errors involving FILESTREAM data. REPAIR_REBUILD performs repairs that have no possibility of data loss, such as repairing missing rows in non-clustered indexes, rebuilding an index, etc. It can’t perform a repair action that in any way may result in data loss.

Also read, How to Restore Database in SQL Server?

Tried REPAIR_ALLOW_DATA_LOSS Option?

If the other options haven’t helped you resolve the problem, you can try to repair the database by running DBCC CHECKDB with the REPAIR_ALLOW_DATA_LOSS option. When the command runs with this option, the server tries to repair all the database consistency errors. It can eliminate the data which might have caused the issue.

Thus, running DBCC CHECKDB with the REPAIR_ALLOW_DATA_LOSS option is effective.

[CAUTION]:

  • Repairing the database by using the REPAIR_ALLOW_DATA_LOSS option might result in data loss. Before executing DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS, make sure that you have a copy of all the database files — MDF (master database file), NDF (secondary database files), LDF (transaction logs), and containers such as file stream folders, full-text catalogs, memory-optimized data, etc.
  • If you’re facing issues with your SQL database due to transaction log corruption, the REPAIR_ALLOW_DATA_LOSS command will rebuild the log. The abrupt rebuilding of the log file may result in transactional inconsistencies.
  • As per the Microsoft recommendation, DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS should only be used as a last resort. Restoring from the last known good backup should always be the primary method for repairing the database.

How to Repair Database If DBCC CHECKDB Doesn’t Work?

If DBCC CHECKDB doesn’t work or involves the risk of data loss, you need to contact a professional SQL database repair service provider, like Stellar. The experts at Stellar can repair all types of corrupt SQL database files — primary (MDF), secondary (NDF), and transaction log (LDF). The seasoned professionals at Stellar first perform the root-cause analysis to find out the cause of corruption. They check if the corruption has caused due to storage disk physical damage or any logical issue, and then repair the database accordingly. They can fix corruption of file headers, tables, data pages, metadata, and page-level corruption, and restore the database in its original form.

Use of Professional MS SQL Repair Software

When DBCC CHECKDB fails, Stellar Repair for MS SQL steps in as a powerful alternative. It excels in identifying and rectifying complex database errors that may be overlooked. By conducting a thorough scan, leveraging advanced algorithms, and ensuring efficient data recovery, Stellar Repair for MS SQL becomes instrumental in salvaging and restoring your SQL Server database. Its user-friendly interface, compatibility across various SQL Server versions, and dedicated support contribute to a seamless and effective recovery process, offering a comprehensive solution where standard methods fall short.

Stellar Download

Additional Reading- How to Recover SQL Server Database with Corrupt Log File?

[BONUS]: Tips to Prevent SQL Database Corruption

Database corruption results in the loss of business data. Here are a few tips that would help you prevent database corruption.

  1. Check the Consistency of the Database regularly

Checking the consistency or integrity of the database at regular intervals is a good practice. This lets you know if there are any errors or issues with the database. To run the consistency check, you can use the DBCC CHECKDB command. If it throws any errors, you can back up your database before it becomes inaccessible, and try to fix issues.

  1. Use Cron Utility

You can use Cron utility, a time-based job scheduler, to schedule periodical tasks of detecting and fixing anomalies in the database.

  1. Update the Database at Regular Intervals

Keep the database updated and patched to maintain its overall health. This helps in preventing the database from potential virus attacks and other threats.

  1. Check the Database File Size and Disk Space

Large-sized database files are prone to corruption. Thus, keep a check on the database file size or split large database files into smaller files to prevent corruption. Also, the availability of disk space contributes to the smooth running of the database and prevents its corruption. So, you must monitor the disk space and allocate/add storage accordingly.

Conclusion

If your SQL database is corrupt and you’re unable to fix it by using the DBCC CHECKDB command, you need to first check the SQL repair service level that you’ve chosen – REPAIR_FAST or REPAIR_REBUILD. Though REPAIR_ALLOW_DATA_LOSS resolves database consistency errors, this option might result in data loss. Thus, it’s best to seek the help of a database repair expert, such as Stellar, for safe and effective recovery of corrupt SQL databases.

Also read,  how to get the activation key of Stellar Repair for MS SQL.

Leave a Reply

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