SQL SERVER – Row Counts of Every Table

This is a blatant rip off of a post from SQL Authority.com with Pinal Dave. Honestly there’s so much great stuff on there. Go there and check it out. I’ve just put it here so I can find it easier.

Tables and row counts.

SELECT 
	SCHEMA_NAME(schema_id) AS [SchemaName],
	[Tables].name AS [TableName],
	SUM([Partitions].[rows]) AS [TotalRowCount]
FROM 
	sys.tables AS [Tables]
	JOIN sys.partitions AS [Partitions]
		ON [Tables].[object_id] = [Partitions].[object_id]
			AND [Partitions].index_id IN ( 0, 1 )
-- WHERE [Tables].name = N'name of the table'
GROUP BY 
	SCHEMA_NAME(schema_id), [Tables].name;