Skip to content

Instantly share code, notes, and snippets.

@GregTrevellick
Last active August 25, 2021 08:32
Show Gist options
  • Save GregTrevellick/cf3937fddceb134375d3ff3f53b4cf33 to your computer and use it in GitHub Desktop.
Save GregTrevellick/cf3937fddceb134375d3ff3f53b4cf33 to your computer and use it in GitHub Desktop.
TSQL get table names and table row counts
SELECT SCHEMA_NAME(A.schema_id) + '.' + A.Name, AVG(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
--ORDER BY AVG(B.rows) DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment