In this post, we will learn how to get all table record counts from the selected database. Here, we are using sys.objects and sys.partitions for getting the record count. Here, we are using join sys.objects with sys.partitions from sys.partitions, we can get row count of table and sys.objects will return the name of a schema (table name).
Here, we are setting the short name A for getting table name and short name B for getting row count. See the below query for getting record count. For this example, set the top 10 rows to get only 10 table names and record counts. See the below example query. Let's start coding.
- SELECT TOP 10 (SCHEMA_NAME(A.schema_id) + '.' + A.Name) AS TableName
- , SUM(B.rows) AS RecordCount
- 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
See the below result screenshot that returns the above query.
All tables' row count screenshot.


saiful islamPosted May 2, 2023, 6:45 AM
Wrong answer
Jason OwensPosted Oct 13, 2022, 4:16 PM
AND A.Name not like 'sys%'
Jason OwensPosted Oct 13, 2022, 4:15 PM
And maybe include this in the WHERE clause :
Jason OwensPosted Oct 13, 2022, 4:15 PM
Aliases A and B. Tut tut.
Debashish SarkarPosted May 28, 2021, 1:18 PM
Thank you Hardik for the help.
Baparoutu VarmaPosted Dec 9, 2020, 2:44 AM
Nice blog. Thanks for sharing.I came across another blog which talk one more way doing same i.e SQL mangement studio. Sharing link: http://sforsuresh.in/getting-rows-count-for-each-table-in-database
Jignesh KumarPosted Aug 15, 2018, 11:26 AM
Nice article ..
Hadshana KamalanathanPosted Jul 15, 2018, 1:26 PM
Thank you for sharing