Skip to content

Instantly share code, notes, and snippets.

@cemerson
Created September 2, 2020 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cemerson/f7cbb11c9a4828822562282b200dafd4 to your computer and use it in GitHub Desktop.
Save cemerson/f7cbb11c9a4828822562282b200dafd4 to your computer and use it in GitHub Desktop.
TSQL get all database rowcounts
CREATE TABLE #counts
(
table_name varchar(255),
row_count int
)
EXEC sp_MSForEachTable @command1='INSERT #counts (table_name, row_count) SELECT ''?'', COUNT(*) FROM ?'
SELECT table_name, row_count FROM #counts ORDER BY row_count DESC
DROP TABLE #counts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment