Table of Content
    SQL Database Repair

    How often should you Check Database Integrity in SQL Server?


    Table of Content

      Summary: You need to check database integrity to ensure that the database is fine. In this blog, you’ll learn how often you can check the database integrity. You’ll know how to run and schedule a database integrity check. You’ll also find about a professional SQL repair tool that can repair the database, if the integrity check fails.

      In SQL Server, the DBCC CHECKDB command verifies the logical and physical integrity of the database. It verifies the integrity of tables, catalogs, disk space allocation, content of indexed views, links between table metadata and file systems, and more.

      How often should you run a database integrity check?

      It is a common practice to do it once a week. However, it depends on the backups. You may want to check the database integrity before doing a database backup. If you back up every day, you may need to check database integrity daily before the backup.

      How to run the database integrity check?

      The DBCC CHECKDB command verifies the database integrity. There are some arguments that you can include with the command, such as:

      • NOINDEX: It excludes the nonclustered index check.
      • NO_INFORMSGS: It excludes informational messages.
      • TABLOCK: It locks the tables to get faster results.
      • ESTIMALTEONLY: It estimates the tempdb space required to run the command.
      • PHYSICAL_ONLY: It checks only the physical structure of the database.

      How to schedule or automate database integrity check?

      The SQL Server Agent is used to schedule and automate tasks. With the SQL Server Agent, you can run T-SQL scripts, including the DBCC CHECKDB command. You can also run the command-line or MDX, XMLA, and DAX scripts.

      • To create a job, in the SQL Server Agent, go to the Jobs node and select New Job.
      SQL Server Agent
      • Write a name for the job and go to the Steps page.
      New Job Window
      • On the step page, press the New button.
      Press the New button
      • In the New Job window, write a step name. In the Type, make sure that the Transact-SQL script is selected.
      • In the Command section, you can use the DBCC command. Then, press OK.
       In New Job Step Window use the dbcc command. Press OK.
      • Go to the Schedules page and press the New button.
      Schedules page and press the New button.
      • Write a new schedule name. You can run the job weekly, daily, or hourly. You can also specify the start time.
      Write a new schedule name. You can run the job weekly, daily, or hourly. You can also specify the start time.

      Is it possible to run maintenance plan wizard to schedule the integrity check?

      Yes, SQL Server includes an option to easily create a maintenance plan in the database. To use the Maintenance Plan Wizard, open SSMS and go to the object explorer. Expand the Management option, right-click the Maintenance Plans, and select the Maintenance Plan Wizard.

      Maintenance Plan Wizard
      • In the Maintenance Plan Wizard window, click Next.
      In the first Maintenance Plan Wizard Windows, press next.
      • Write a name for the maintenance plan. Select an account to run the job. By default, the SQL Server Agent service account is used. Press the Change button to change the schedule.
      Write a name for the Maintenance plan. Select an account to run the job. By default, the SQL Server Agent service account is used. Press the Change button to change the schedule.
      • Select weekly, daily, or hourly by using the Occurs box, configure how often do you want to run the maintenance check, and press OK.
       run the maintenance check and press OK.
      • Press Next. In Select Maintenance Tasks, select the Check Database Integrity option and press Next.
      select the Check database integrity under select maintenance task wizard
      • In the Select Maintenance Task Order window, press Next.
      under Maintenance Plan Wizard select check database integrity
      • Select the databases to maintain and press Next.
      define database check integrity
      • You can choose a path for the report.
      choose a path for the report.
      • Finally, press the Finish button.
      Complete the wizard under Mainteance Plan Wizard actions
      • In the final window if everything is green, close the wizard.
      Maintenance Plan Wizard success
      • In SQL Server Agent, in the Jobs node, you will see the new job created.
       SQL Server Agents new job creation

      What to do if the database integrity fails?

      The DBCC CHECKDB command may fail. If that happens, you can try to use the command with the REPAIR_REBUILD option.

      If that option fails, you can try to repair the database with the REPAIR _ALLOW_DATA_LOSS or using a third-party software, such as Stellar Repair for MS SQL. This software can easily repair the database (mdf) file without any data loss. You may need to bring the database offline to repair it.

      Take offline

      Conclusion

      In this article, we have learned how often we can run the database integrity check. We also discussed how to run and schedule a database integrity check. If the integrity check fails, you need to repair the database. To avoid data loss, you can use a third-party SQL repair tool, such as Stellar Repair for MS SQL.  

      Was this article helpful?

      No NO

      About The Author

      Bharat Bhushan linkdin

      Bharat Bhushan is an experienced technical Marketer working at Stellar Data Recovery - expertise in data care. He is skilled in Microsoft Exchange Database, MSSQL Database troubleshooting & data warehousing. He is a Management Post Graduate having a strong grip in Technology & certified in SAP-SD, Oracle 10g & Informatica Powercenter 9.1.

      Leave a comment

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

      Image Captcha
      Refresh Image Captcha

      Enter Captcha Here :

      Related Posts

      WHY STELLAR® IS GLOBAL LEADER

      Why Choose Stellar?

      • 0M+

        Customers

      • 0+

        Years of Excellence

      • 0+

        R&D Engineers

      • 0+

        Countries

      • 0+

        PARTNERS

      • 0+

        Awards Received