How to fix SQL Server database consistency errors?

SQL Server provides its users with built-in methods or solutions when they encounter different type of errors. These errors create problems to the users as the database goes inaccessible. For such conditions, the user goes for DBCC CHECKDB help to check the logical integrity of the database. But sometimes, while running the command, an error may appear like this;

2010-03-31 22:07:06.34 spid53      DBCC CHECKDB (mydb) executed by MYDOMAIN\theuser found 15 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 0 seconds.  Internal database snapshot has split point LSN = 00000026:0000089d:0001 and first LSN = 00000026:0000089c:0001.  This is an informational message only. No user action is required.

This is a general type of error log. While executing DBCC CHECKDB, different type of data consistency errors may be encountered. This error log shows the number of consistency errors. Internal database snapshot is for online DBCC CHECKDB as it is used to present a consistent data to check. These errors indicate corruption in SQL server database and makes data inaccessible to the user. Hence, indicates a dire need to resolve these consistency errors to get back access to the SQL Server data.

Common reasons for data consistency in SQL server database

DBCC CHECKDB, a set of commands checks the integrity of the database using logical commands. Due to any error or disturbance, when this operation fails, you get a consistency error log. In database consistency, MS SQL server primary database and transactional log shows different data. Some of the reasons for this consistency may include

  • Less or no disk space
  • Crash of SQL Server (Bugs inside database code)
  • Hardware failure
  • Power outages
  • Upgrading SQL version
  • Network issues
  • File system corruption
  • Corrupted pages in memory
  • Issue with SQL Server Engine

One or more reasons might be responsible for the error. The error can be prevented by not overlooking the reasons for it. Being careful about the different causes that might affect your database is helpful any day. Once the reason is specified or known, you can move for the solution. Even if the reason is not completely identified, you may try to resolve data consistency errors by yourself. The problem always holds a solution for it.

Manual tricks to solve data consistency errors in SQL Server database

To solve the issue, you must primarily check for any fresh backup. If the valid, full and updated backup is available, you can restore the data. But such conditions are rare when a user is looking for some solution online. What to do when you do not have any backup? The solution is definitely there. The help is provided by Microsoft like DBCC CHKDB and DBCCDBREPAIR which are the database console commands. You can run these commands on SQL Server Management Studio to repair corrupt SQL Server database.

Using SQL Server Management Studio application

To start with you need to have SQL Server Management Studio application. This is a tool provided by Microsoft to manage and configure all components in Microsoft SQL Server. It comes with SQL Server itself. Now to resolve the SQL Server database corruption, follow the steps under.

Step1 Open the Microsoft SQL Server Management Studio application on your system.

Step2 On a window opened, click New Query icon.

A new query page will get opened.

Step3 Next, on the new query page, write the following SQL Scripts

EXEC sp_resetstatus [YourDatabase];
ALTER DATABASE [YourDatabase] SET EMERGENCY
DBCC checkdb ([YourDatabase])
ALTER DATABASE [YourDatabase] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC DATABASE ([YourDatabase], REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE [YourDatabase] SET MULTI_USER

Note: No change for the above query is required except for replacing ‘Your Database’ with the original name of your database file.

Step4 Click on the Execute tab. This is the final step.

You can try checking your database after the execution of this tool. The database may be accessible now. One more method to repair corrupt database is discussed here.

Using DBCC scripts

You can use DBCC scripts in SQL Server Management Studios that helps in detecting and fixing SQL database consistency errors. It helps SQL administrator to have a consistency check of SQL database in index pages, table and disk allocation structures. An example is shown below –

If you need to recover database table named ABC production, use these T-SQL script:

DBCC CHECKTABLE (XYZ production, REPAIR REBUILD)

It will rebuild missing or corrupt indexes of ABC Production table. It also restores all missing rows of non-clustered indexes in XYZ Production table.

Checking Windows System Event Log

Users can perform a check over the Windows System Event Log and if there Error Event logs available, then problem can be I/O related which can be easily resolved by performing the provided resolution for the particular error log. Other options would be running a check over system drivers, system level or driver issues. Moreover, confirming the I/O requirements for the installed SQL Server is also recommended.

Perform DBCC CHECKDB with Minimum Repair

As mentioned in the consistency error message while running the DBCC CHECKDB command for the SQL Database, users can try to run the minimum repair option to resolve all errors from running this command.

“CHECKDB found 0 allocation errors and 15 consistency errors in database ‘mydb’.
repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKDB (mydb)”

In basic language, it means that users can try to find out the minimum repair level to fix the error which he can achieve by trying to run DBCC CHECKTABLE command for each SQL table with error.

Check Hardware Requirements

Users can take help from the hardware/device manufacturer to ensure that the installed hardware conforms with the I/O requirements of the SQL Server as well as other device drivers and installed software are updated to the latest version.

Check File System Integrity with CHKDSK Command

Using CHKDSK command for checking the file system integrity would be a good trial. This command is effective in listing and correcting the errors available on the disks.

chkdsk [drive**:] [/p**] [/r]

These manual tricks are helpful in some cases, for minimum level of corruption but not always beneficial and trustworthy. Backup option is useful in some cases but for corrupt database elements cases, it does not work actually. By the time you decide to backup your data, corruption related to database elements has already crashed your backup as well.

When the degree of corruption is of high level, no manual trick works efficiently. While using repair option using scripts, there is always a chance of data loss. The method used is also very complex and time consuming. All these drawbacks of manual tricks call for an alternative solution.

Using a professional solution to resolve SQL Server database consistency error

Manual methods are certainly aid for the user in his bad time. The user can try it if unknown to large corruption. Sometimes, manual methods do work if the corruption is within control or small. With the learning of how manual methods work and response, users are encouraged to find a more reliable and secure alternative. The search is over with a reliable and efficient third-party SQL Database Repair tool. It is a highly innovative tool that recovers data from corrupt SQL server database within minutes. The tool is bind to provide high accuracy with recovery of file objects like tables, views, triggers, programmability, default, etc. The interface of the tool is quite user-friendly. Even a novice user is able to handle it easily. No technical expertise is required for the tool. SQL Database Repair tool is the best solution for accurate and secure recovery of data from corrupt SQL Server database.

Download Now

Conclusion

Along with the discussion of data consistency errors and its causes, the user has come across the manual solution approaches, i.e. using DBCC CHECKDB repair command, restore from update and valid backup, checking file system integrity with CHKDSK command, running DBCC scripts, etc. It holds both benefits and drawbacks. However, a third-party tool SQL Database Repair is a savior in the worse conditions of database corruption.