May 23, 2015

How to Check Database Integrity in SQL

Check Database Integrity for All Databases of Server

-- Single Database -- Use (?) for all the Database.

EXEC sp_msforeachdb 'DBCC CHECKDB(''DB_Name'')'

-- SQL 2005

EXEC sp_MSforeachDB 'DBCC CHECKDB (?) WITH ALL_ERRORMSGS, DATA_PURITY'

-- SQL 2008 and later

EXEC sp_MSforeachDB 'DBCC CHECKDB (?) WITH ALL_ERRORMSGS, EXTENDED_LOGICAL_CHECKS, DATA_PURITY'

No comments:

Post a Comment