How to list row count of each table in the database. Some equivalent of
select count(*) from table1
select count(*) from table2
...
select count(*) from tableN
I will post a solution but other approaches are welcome
How to list row count of each table in the database. Some equivalent of
select count(*) from table1
select count(*) from table2
...
select count(*) from tableN
I will post a solution but other approaches are welcome
A snippet I found at http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=21021 that helped me:
This approaches uses string concatenation to produce a statement with all tables and their counts dynamically, like the example(s) given in the original question:
Finally this is executed with
EXEC
:If you're using SQL Server 2005 and up, you can also use this:
In my opinion, it's easier to handle than the
sp_msforeachtable
output.The accepted answer didn't work for me on Azure SQL, here's one that did, it's super fast and did exactly what I wanted:
If you use MySQL >4.x you can use this:
Keep in mind that for some storage engines, TABLE_ROWS is an approximation.
Fastest way to find row count of all tables in SQL Refreence (http://www.codeproject.com/Tips/811017/Fastest-way-to-find-row-count-of-all-tables-in-SQL)