Get row count from all tables

29 01 2012

The following T-SQL script generates a view of all table names and the number of rows contained in each table for the current SQL database.

SELECT o.name 'TableName', p.rows 'Rows'
FROM sys.objects o
JOIN sys.partitions p ON o.object_id = p.object_id
WHERE (o.type = 'U')
AND (p.index_id IN (0,1))
ORDER BY p.rows DESC

I found this information here.

Advertisements