Historical article
- Original title: Quickly Retrieving the Row Count for All Tables
- Author: Brian Knight
- Original publication date: December 21, 2005
- Originally published on: White Knight Technology
- Preservation note: This partial recovery is limited to the material verified in the Wayback snapshot evidence.
Archive provenance: White Knight Technology Historical Archive
The sp_msforeachtable stored procedure could loop through every table in a database and perform an action, including obtaining a record count for each table. The problem with that output was that it could not be sorted without additional customization, so another approach was needed.
sysindexes held a row for each index in the database along with an estimated number of rows for the table. That estimate was useful as a starting point, but it was not guaranteed to be current.
Recovery limitations
The Wayback evidence used for this recovery truncates the original final query after the word select. The query is therefore unrecovered and has intentionally not been reconstructed or completed here.
2026 Update
This is a historical, partial article about legacy SQL Server internals. No replacement query has been added because doing so would be new guidance rather than recovered White Knight Technology content. Consult documentation for the supported SQL Server version before choosing a current row-count method.