DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • DuckDB for Python Developers
  • Custom Model Context Protocol (MCP) for NL2SQL: A Rigorous Evaluation Framework on Oracle Database
  • Chat with Your Oracle Database: SQLcl MCP + GitHub Copilot
  • Push Filters Down, Not Up: The Data Layer Design Principle Most Developers Learn Too Late

Trending

  • DZone's Article Submission Guidelines
  • How to Submit a Post to DZone
  • A Deep Dive into Tracing Agentic Workflows (Part 1)
  • From APIs to Actions: Rethinking Back-End Design for Agents
  1. DZone
  2. Data Engineering
  3. Databases
  4. Frequency for Performing Database Integrity Checks in SQL Server

Frequency for Performing Database Integrity Checks in SQL Server

This article will explore how to handle the database integrity check using SQL Server. We will check how often we can run the commands to check it.

By 
Daniel Calbimonte user avatar
Daniel Calbimonte
·
Jun. 27, 23 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
5.4K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we will learn some recommendations for checking the database's integrity in an SQL Server. We will see how often we should perform an integrity check and how to automate this process.

What Is Database Integrity?

SQL Server can have problems with the tables, indexes, catalogs, etc. When we check integrity, we verify that there are no consistency errors in the database.

How Can I Check Database Integrity in a Database?

There are several commands to check the integrity of the database.

  • The DBCC CHECKDB checks consistency errors in the database.
  • Also, we have the DBCC CHECKTABLE, which checks the integrity of a selected table.
  • In addition, we have the DBCC CHECKCATALOG that checks that there are no errors in a database catalog.
  • There are other commands like the DBCC CHECKFILEGROUP and the DBCC CHECKIDENT to check the integrity of a database filegroup and the IDENTITY values (auto-numeric values).

Why the Integrity Errors Occur

These errors can be caused by hardware problems (hard drives, hardware overheating, power-outage problems) and software problems (viruses, malware, and malicious software).

How To Check the Integrity of the Databases or Their Objects

The following example shows how to check the database integrity of the database:

MS SQL
 
DBCC CHECKDB


The next example shows how to check the database integrity excluding informational messages:

MS SQL
 
DBCC CHECKDB WITH NO_INFOMSGS;


Also, we have an example to show the database integrity, but excluding the indexes:

MS SQL
 
DBCC CHECKDB (stellardb, NOINDEX);


In addition, we check the integrity of a table. The following example shows how to do it:

MS SQL
 
DBCC CHECKTABLE ('dbo.sales'); 

GO


How Often Should We Check the Database’s Integrity?

We should verify the database integrity daily if the data is critical and we have a lot of transactions per day.

If the information is not so critical and it does not change to match, we can schedule to run it weekly.

If the data is static, we can run the integrity check every month if the data is not critical.

Doing an integrity check in SQL Server consumes a lot of resources. It is recommended to run these commands at night or when not so many users are using the software.

Otherwise, the transactions and reports will take too long to execute.

How To Schedule Integrity Checks in SQL Server

For this example, we will need to have the SQL Server Management Studio (SSMS). 

Open the SSMS, click the Object Explorer, and look for the SQL Server Agent>Jobs.SQL Server Agent>Jobs

In Jobs, right-click and select New Job.

New Job

The jobs will help you to schedule the task and execute them immediately. On the General page, write a name and optionally a description for the job.

General

 On the Steps page, press the New button to create a new job.Steps

Write a name for the step, and in the Command textbox, write the DBCC command you want to check for integrity. Make sure that the type is Transact SQL script (T-SQL).

Transact SQL script (T-SQL)

On the Schedule page, write a Name for the schedule. Select the Recurring Schedule type. In the Occurs option, select Daily.

select Daily

Use the Maintenance Wizard To Check the Database's Integrity

There is a nice option to run the integrity check without writing code. This method uses a Wizard. To run it, in the Maintenance Plans, right-click and select Maintenance Plan Wizard.

Maintenance Plans

In the SQL Server Maintenance Plan Wizard, press the Next button.

press the Next button

In the Select Maintenance Tasks, select Check Database Integrity and press Next.

 Select Maintenance Tasks

In the Select Maintenance Task Order, we only have one option selected. Select that one and press Next.

Select Maintenance Task Order

In Databases, select the database you want to check the integrity of and press Next.

select database

In the Select Report Options, specify the path for the report. Check the E-mail report To, if necessary.

In the Select Report Options, specify the path for the report


In Complete the Wizard, press Finish.

press finish

In the Maintenance Plan Wizard Progress, press close.

Maintenance Plan Wizard Progress

Other Tools

There are also some third-party tools like the Stellar Repair for MS SQL, which can be used in case of integrity errors in the SQL Server database. These tools can be used to repair the database and maintain its integrity. The tool works at the file level and repairs the database in case of integrity errors.

Conclusion

To conclude, we can say that the integrity of SQL Server can be fixed. In this article, we explain what data integrity is, and we also learned how to detect problems using different commands. Also, we learned how often we should check the database's integrity. Basically, for critical databases, the integrity check should be done daily.  In addition, we learned how to schedule the integrity checks. Finally, we learned how to repair the database using third-party tools.

Database Integrity (operating system) sql

Opinions expressed by DZone contributors are their own.

Related

  • DuckDB for Python Developers
  • Custom Model Context Protocol (MCP) for NL2SQL: A Rigorous Evaluation Framework on Oracle Database
  • Chat with Your Oracle Database: SQLcl MCP + GitHub Copilot
  • Push Filters Down, Not Up: The Data Layer Design Principle Most Developers Learn Too Late

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook