How to Get Row Counts for all Tables in your SQL Database

This is the simplest method to get the row counts of all tables in your SQL Server database. Might be useful when you are doing the data testing over your BI project. 


  select schema_name(tab.schema_id) , tab.name as [table],
       sum(part.rows) as [rows]
   from sys.tables as tab
        inner join sys.partitions as part
            on tab.object_id = part.object_id
where part.index_id IN (10// 0Table without PK, 1table with PK
and schema_name(tab.schema_id) = 'dbo' 
group by schema_name(tab.schema_id) , tab.name

--order by sum(part.rows) desc 

Comments