Finding the number of rows of all tables in a SQL Server database

The following query finds all tables in a schema, ordered by row count:

SELECT
    sysobjects.*
    , sysindexes.Rows
FROM
    sysobjects
    INNER JOIN sysindexes
    ON sysobjects.id = sysindexes.id
WHERE
    type = 'U'
    AND sysindexes.IndId < 2
ORDER BY sysindexes.Rows desc

Leave a Reply

Your email address will not be published. Required fields are marked *