Home » SQL » Check the Integrity of SQL Server Database – Solution For DBAs Common Issue

Check the Integrity of SQL Server Database – Solution For DBAs Common Issue

  author
Ravindra Singh   
Published: Nov 20, 2018 • SQL • 5 Min Read

Check the Integrity of SQL Server Database

I am the SQL server administrator who handles several SQL servers where on each server there exists multiple databases. My business higher authority advised me to check the integrity of SQL server database. Alike all, initially I also used CheckDB command but, something is going wrong. So, can anyone assist me with proper solution for checking data integrity in SQL server?

Whenever a DBA talks regarding SQL Server integrity check, the conversation ends with CheckDB. Well, not worry just refresh your mind and take it to relax state! Simply go through this entire post, which is dedicated towards giving assistance to check the integrity of SQL server database. One is also going to find solution for fixing the problems caused at the time of running CheckDB command.

Quick Overview on Database Integrity Check

The task comprises of analyzes of allocation and structural integrity for all the objects, present in a particular database. It includes the checking of database indexes. Of course, its a good habit to check the SQL server database integrity on a specified schedule. Sometimes a sudden problem might also occur where you have to perform integrity check to assure that your database is safe.

Get to Known About DBCC CheckDB in Brief

The CheckDB command is like medicine for problems to prevent complications and fix possible damages in Microsoft SQL server. But, there is major need to use this command with caution! Administrators might also the lose content of the server, if they are using this command without any backup strategy. Basically, CheckBD is a Database console command, which is categorized as the Validation DBCC.

It is a necessary step for maintenance of entire instances in the SQL Server, where one can determine the issues. If a problem can be resolved with this command, it will definitely fix it without causing any error. DBAs will be able to anticipate issues, if they are regularly executing DBSS CheckDB without any break.

Objective to Initiate CheckDB – There exists two main roles of this command and they are pointed below :

1. Check the integrity of SQL server database
2. Auto-correction on addressing any problem

It checks only the database structure, not its consistency. The DBCC CheckDB command goes in three phases when it is executed :

1. Verification of allocated structures
2. Verification of table consistency & indexes
3. Verification of entire system catalogs

CheckDB comprises of an option that enables it to make corrections in the database structure. However, this might lead to loss of repaired pages from the allocated data. The name of this option is REPAIR_ALLOW_DATA_LOSS, which converts damaged page into the new one. With this technique, it is possible to hold database integrity in the Microsoft SQL server.

Important Note – Here we are talking about physical structure, not about integrity. This is the reason due to which administrators are facing data loss when they checking MS SQL server database integrity via CheckDB.

When the command gets executed, a verification-based on backups should be created in order to determine and regain back the lost data. Now, next comes REPAIR_REBUILD option in which correction of non-clustered indexes takes place. There is no chance of losing data with this option but, there exists few limitations in it.

  • The database needs to be in SINGLE_USER mode to accomplish repairing
  • CheckDB command is unable to fix errors related to system tables & PFS pages

When & Where To Check SQL Server Database Integrity?

SQL Server experts from different corners of the world suggest administrators to attempt this task daily in the evening. This could nearly be impossible because of the hectic business operations in regular life. Still, they recommended admins to go for weekly check, if daily is not possible. Apart from this, following are some interesting facts related to checking of SQL server database integrity :

  • The maintenance plan of SQL server ignores the TempDB. In case it becomes corrupted, the instance will get terminated.
  • Execution of CheckDB on master SQL database leads to running of command on mssqlsystemresource database too.

Finally Its Time to Execute CheckDB Command

Keep one thing in mind that CheckDB command does not execute directly on the database. For this, a secretive database snapshot is originated and then, the entire procedure is dependent on this snapshot. Several users realize this fact when they are unsuccessful in first attempt of command execution. Well, if one gets fail in creating a snapshot, they can refer following three options :

1. Troubleshoot the permission for snapshot creation
2. Run CheckDB with TABLOCK option. This could lead to issues because database is going to be target of locks.
3. Attempt a job creation with help of following guidelines :
a) Create a database snapshot
b) Execute the DBCC CheckDB on this newly created snapshot.

Hope You Got Solution To Your Problem

Different webpages might give DBAs knowledge regarding use of DBCC CheckDB command but, they do not tell about conditions to use it. Unawareness of these conditions to check SQL server database integrity leads to error occurrence when administrators execute CheckDB command. Therefore, the post majorly focused on the conditions that are required before executing integrity command.

Check More Similar Post:
Disaster Recovery Plan SQL Server

By Ravindra Singh

Ravindra Singh is a seasoned professional who wears two essential hats in the digital world - as a Digital Marketing Consultant and a Content Strategist. His expertise lies in formulating and executing result-driven digital marketing strategies. Simultaneously, his strategic approach to content ensures that brands deliver compelling and engaging narratives.