Archive for the ‘DBCC CHECKDB()’ Category

How to perform database integrity check on all the required databases?

You understand that it is recommended that you run the database integrity check at least once a week to check the logical and physical integrity of all the objects in all databases. You want to schedule a SQL Server Agent job to automate this process before the Sunday morning backups, the following script can be used to help you to perform DBCC CHECKDB() on all databases:

-- Run DBCC CHECKDB() on the required databases
EXECUTE sp_MSforeachdb 'USE [?]
IF DB_NAME() NOT IN (''tempdb'')