Home » Techtalk » SQL Server » How to Fix SQL Database Error if DBCC CHECKDB Not Working?

How to Fix SQL Database Error if DBCC CHECKDB Not Working?

Admin | Modified: 2021-11-30T12:39:58+00:00| SQL Server | 4 Minutes Reading

When your SQL Server Database encounters a consistency error or it gets damaged, you can use the DBCC CHECKDB command and learn more about the database problem. The DBCC CHECKDB command checks for SQL database physical and logical consistency problems. It examines the consistency of database pages, layers, distribution pages, index relationships, and system registry configuration integrity. Read the full article to understand the mistakes and the actions that need to be taken when DBCC CHECKDB not working.

DBCC CHECKDB (Affected_DBMain) WITH NO_INFOMSGS, ALL_ERRORMSGS

This command tells you the basic level of repair required to solve the database issues.

For example, the command output might look similar to the result below:

CHECKDB found 0 satisfaction errors and 10 consistency errors in Affected_DBMain’s database. Repair_allow_data_loss is the minimum repair error for DBCC CHECKDB (Affected_DBMain) errors

How to Solve SQL Database Issue by DBCC CHECKDB Command?

SQL Server provides three levels of repair-REPAIR_FAST, REPAIR_REBUILD, and REPAIR_ALLOW_DATA_LOSS. According to DBCC CHECKDB recommendations of the required repair level, you can execute the DBCC CHECKDB command to repair the database.

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 Not Working to Solve SQL Server Issues?

If DBCC CHECKDB does not work, it means you have used the REPAIR_FAST repair option as it will not perform any repairs. The REPAIR_FAST option is only used to provide backwards compatibility when attempting to repair the database with other repair options.

If database errors include FILESTREAM data, you may not be able to use REPAIR_REBUILD to repair the database. REPAIR_REBUILD performs repairs where data loss is not possible, such as repairing missing rows in unrelated indexes, rebuild indexes, etc. It can’t perform any repairs that could cause data loss.

Fix SQL Database Error by REPAIR_ALLOW_DATA_LOSS Command

If other options do not help you solve the problem, you can try repairing the database by running DBCC CHECKDB with the option REPAIR_ALLOW_DATA_LOSS. When the command is executed with this option, the server will try to fix database consistency errors. It can delete data that could cause problems. Therefore, it is a risk to run DBCC CHECKDB with the REPAIR_ALLOW_DATA_LOSS option.

Limitations of REPAIR_ALLOW_DATA_LOSS Command

  • Repairing the database with the REPAIR_ALLOW_DATA_LOSS option may result in data loss. Before using REPAIR_ALLOW_DATA_LOSS to execute DBCC CHECKDB, please make sure you have a copy of each database file – MDF (primary database file), NDF (secondary database file ), LDF (trade log), and files such as file stream folders, full text instructions, data memory optimization, etc.
  • If there is a problem with the SQL database due to a damaged trade log, the REPAIR_ALLOW_DATA_LOSS command will rebuild the log. A sudden rebuild of the log file may cause inconsistencies.
  • Microsoft’s recommendation that DBCC CHECKDB by REPAIR_ALLOW_DATA_LOSS should only be used as a last resort. Restoring from the last well-known backup should be the primary way to repair the database.

Professional Solution to Fix SQL Server Database Corruption Issue

If DBCC CHECKDB is not working or there is a risk of data loss, you need to try a professional solution: SQL Database Repair Tool. This tool can repair all types of damaged primary SQL database (MDF) and secondary SQL database (NDF) file.

Download Now Purchase Now

Step by Step Guide to Recover Corrupted SQL Database Files

This tool check whether the damage was caused by physical damage to the storage disk or any logical problem, and then repair the database accordingly. They can repair file headers, tables, data pages, metadata, and page-level damage, and restore the database to its original format.

Conclusion

If your SQL database is corrupted and you cannot use the DBCC CHECKDB command to repair it, you must first check the level of SQL repair method you selected REPAIR_FAST or REPAIR_REBUILD. While REPAIR_ALLOW_DATA_LOSS fixes database consistency errors, this option may cause data loss. Therefore, it is best to enlist the help of a database repair software to safely and efficiently restore a damaged SQL database.