How to Get Row Count Of All The Tables In SQL Server Database

Example: Need to do a quick row count for all the tables in a database.

This is a quick way to find the row count for all the tables in a database. The Cursor with Count(*) can be slow as it has to count rows for each of the table.


USE YourDBName
GO
SELECT OBJECT_NAME(id) AS TableName,
       rowcnt          AS [RowCount]
FROM   sysindexes s
       INNER JOIN sys.tables t
               ON s.id = t.OBJECT_ID
WHERE  s.indid IN ( 0, 1, 255 )
       AND is_ms_shipped = 0

I ran above query on Test DB and got below information:
























Fig 1: Get Row Count for all the Tables in SQL Server Database                                                    

Comments

Popular posts from this blog

Azure SQL, Cloud Migration and Modernization

Intro to Azure Core Storage Services

Apache Cassandra in the Cloud : Amazon Keyspaces and Datastax Astra