Sign Up Now!Log In
RachelW 7/30/2018 2:52:08 PM

Run DBCC CHECKTABLE against all the tables in a database

* This article, and all our great SQL (General) documentation, Is available on the SQL (General) menu

This is a short piece of code that will run DBCC CHECKTABLE against all the tables in a database. 

In case you were wondering, DBCC CHECKDB does the following:

Runs DBCC CHECKALLOC on the database.
Runs DBCC CHECKTABLE on every table and view in the database.
Validates the Service Broker data in the database.
Runs DBCC CHECKCATALOG on the database.
Validates the contents of every indexed view in the database.

and DBCC CHECK TABLE does these tasks:

Index, in-row, LOB, and row-overflow data pages are correctly linked.
Indexes are in their correct sort order.
Pointers are consistent.
The data on each page is reasonable, included computed columns.
Page offsets are reasonable.
Every row in the base table has a matching row in each non-clustered index, and vice-versa.
Every row in a partitioned table or index is in the correct partition.

So, running CHECKDB is more comprehensive.


Version: Unknown or N/A
Section: SQL Scripts