Query – AumTechHub.Com https://aumtechhub.com Just share it!!! Sat, 29 Aug 2020 00:16:02 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 179596041 How to get total row count of all database tables? https://aumtechhub.com/how-to-get-total-row-count-of-all-database-tables/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-get-total-row-count-of-all-database-tables Thu, 27 Aug 2020 04:29:27 +0000 http://aumtechhub.com/?p=54 This script will create a temp table and store the name of the database table and total row counts for each table in the database.

CREATE TABLE #TableRowCounts
(
TableName varchar(150),
TotalRows int
)

EXEC sp_MSForEachTable @command1=’INSERT #TableRowCounts (TableName, TotalRows) SELECT ”?”, COUNT(*) FROM ?’

SELECT TableName, TotalRows FROM #TableRowCounts ORDER BY TableName, TotalRows DESC

DROP TABLE #TableRowCounts

More on sp_MSForEachTable

]]>
54