Easy way to fetch row count for all tables in a SQL database

This is just a quick post for, with a old method for fetching the row count for a entire database – for future reference (Works in Azure – doesn’t require stored proc)

SELECT 
	[SchemaID]	= t.schema_id
	,[SchemaName]	= (SELECT top 1 name from sys.schemas s where t.schema_id = s.schema_id)
	,[TableName]	= t.name
	,[RowCount]	= s.row_count 
FROM sys.tables t

JOIN sys.dm_db_partition_stats s
	ON t.object_id = s.object_id
	AND t.type_desc = 'USER_TABLE'
	AND t.name not like '%dss%'
	AND s.index_id IN (0,1)

WHERE 1=1
	
order by s.row_count desc

You may also like...

Leave a Reply

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