Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get row count of all tables in database: SQL Server [duplicate]

Tags:

sql

sql-server

I'm trying to familiarize myself with a large database and search for relevant information among the many tables. I often find myself calling up a table, to see if there is relevant data inside, only to find that the table has no records.

How to quickly call up a list of all tables and the number of records contained therein? I'm using sql server 2008.

Thanks!

Related Question: How do I QUICKLY check many sql database tables and views to see if they are not empty or contain records

like image 231
Charles M Avatar asked Mar 21 '14 02:03

Charles M


2 Answers

Right click on database -> Reports -> Standard Reports -> Disk usage by Top Tables

enter image description here

like image 158
Mitch Wheat Avatar answered Nov 15 '22 09:11

Mitch Wheat


If you want to use a query, you can use this (note: it's using an undocumented stored procedure sp_msforeachtable):

create table #tempcount (tablename nvarchar(128), record_count bigint)
EXEC sp_msforeachtable 'insert #tempcount select ''?'', count(*) from ? with (nolock)'
select * from #tempcount
drop table #tempcount
like image 37
Szymon Avatar answered Nov 15 '22 11:11

Szymon