How to take count rows of all tables in a database?


If you need to take row count (number of rows) of all tables in a database, please use following code:

USE <DATABASE NAME>
GO
SELECT      SCHEMA_NAME(A.schema_id) + '.' +
        A.Name, SUM(B.rows) AS 'RowCount'
FROM        sys.objects A
INNER JOIN sys.partitions B ON A.object_id = B.object_id
WHERE       A.type = 'U'
GROUP BY    A.schema_id, A.Name
GO

























Comments