How to list Table Names and Count table Rows in HEAT Help Desk

Version 1

    Details

    What is the SQL syntax to list out all the Table Names and the count of Rows in each table?


    Resolution

    Run the following through SQL Server Management Studio:

    SELECT

        [TableName] = so.name,

        [RowCount] = MAX(si.rows)

    FROM

        sysobjects so,

        sysindexes si

    WHERE

        so.xtype = 'U'

        AND

        si.id = OBJECT_ID(so.name)

    GROUP BY

        so.name

    ORDER BY

        2 DESC