RachelW
4Penny.net
Points: 7353

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.

 

4Penny.net
Version: Unknown or N/A
Section: SQL Scripts
Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3