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
Fig 1: Get Row Count for all the Tables in SQL Server Database
 
 
Comments
Post a Comment