Home
About
Search
Welcome to M-Files Empower – our new support experience. We'd love to hear what you think!Give feedback
Home/Support and troubleshooting/Troubleshooting/FAQ/General questions

SQL Server: How to automate to run DBCC CheckDB command periodically

Last updated on 9 December 2024

Admin

Overview

It is recommended to check the SQL database regularly e.g. once a week by running the dbcc checkdb -command.

Running this command periodically helps to detect possible underlying corruption more quickly in the database files as this may remain undetected for long periods and thus affecting also backups.

Solution

You can configure the database maintenance plan in SQL Management Studio to automate the SQL Server DBCC CheckDB process.

  1. To create a maintenance plan, Launch SQL Server Management studio -> Right-click on Management -> 'Select New Maintenance Plan…'
  2. Specify the appropriate name of the maintenance plan
  3. Drag the 'Check Database Integrity Task' from the maintenance plan toolbox and drop it on the Maintenance plan designer window
  4. To configure the SQL Server DBCC CheckDB, double click on 'Check Database Integrity Task'. A dialog box opens
  5. Configure the connection, click on 'New..'. Specify the Connection Name in the 'Connection name' textbox and specify the hostname in 'Specify the following to connect to SQL Server data' text box. 
  6. Click OK to create the connection and close the dialog box
  7. In Databases: choose 'All User Databases' and exclude the databases that are not ONLINE, check  the option 'Ignore databases where the state is not an online' and click OK
  8. Select options 'Include indexes' and 'Physical Only'
  9. Click OK to save the configuration of the 'Check database integrity task' and close the dialog box
  10. Configure the job schedule, click on the calendar icon in maintenance plan designer
  11. In the New Job Schedule dialog box, set the values of parameters e.g. shown below:

Schedule Type: Recurring

Occurs: Weekly

Recurs every: 1 week on Saturday

Occurs once at 0:00:00

If you click 'Reporting and Logging' icon in the Maintenance plan designer, you can define where the reports and logs are stored.

For the more detailed steps and pictures, please check this web page:

https://www.sqlshack.com/automate-the-sql-server-dbcc-checkdb-command-using-maintenance-plans/

Please note that M-Files is not responsible of content of 3rd party web pages.

Please see also the following article:

/article/Using-DBCC-CHECKDB-to-check-SQL-database-integrity

Still need help?

On this page