sql-server

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.

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

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


Abhith Rajan

Written byAbhith Rajan
Abhith Rajan is a software engineer by day and a full-stack developer by night. He's coding for almost a decade now. He codes 🧑‍💻, write ✍️, learn 📖 and advocate 👍.
Connect

Is this page helpful?

Related SnippetsView All

Related ArticlesView All

Related VideosView All

High Availability and SLA for Azure SQL Managed Instance

Using SQL Data Sync for Bidirectional Data Replication in SQL Server & Azure SQL DBs | Data Exposed

Build fast, scalable data system on Azure SQL Database Hyperscale | Clearent

Related Tools & ServicesView All

sqlfum.pt

sequel fumpt

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

SmarterASP.net - Unlimited ASP.NET Web Hosting

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