Fetch Row Count for All Tables in a SQL SERVER

Using a short query we can list all the tables in the database along with the number of records in each table.

Abhith Rajan
Abhith RajanMarch 11, 2018 · 1 min read · Last Updated:

Just execute the below query in the database to see the list of tables and number of records in each table.

1SELECT t.name, s.row_count
2FROM sys.tables t
3 JOIN sys.dm_db_partition_stats s
4ON t.object_id = s.object_id
5 AND t.type_desc = 'USER_TABLE'
6 AND s.index_id IN (0,1)

Abhith Rajan

Written by Abhith Rajan
Abhith Rajan is an aspiring software engineer with more than nine years of experience and has a proven successful track record of delivering technology-based products and services.

This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub

Related SnippetsView All

Related ArticlesView All

Related VideosView All

SQL Server 2017 Graph Database

Azure SQL Game Changers for Developers | BDL112

Related StoriesView All

Related Tools & ServicesView All


sequel fumpt

sqlfmt is an online SQL formatter. It is pronounced sequel fumpt. Its purpose is to beautifully format SQL statements.

SmarterASP.net - Unlimited ASP.NET Web Hosting

ASP.NET Hosting by SmarterASP.net. Unlimited ASP.NET Hosting Plans Starting at $2.95 a month.