Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 sql script for getting table count and row count

Author  Topic 

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2011-07-29 : 04:51:46
Hi Team,
i have a requirement like i need to get all the tables in a table, and row count of each table. is there any script for that? can you kindly suggest me in this? there are lot many tables, else i can use below one like

select * from information_schema.tables
and
select count(*) from <all tables one by one>
please help me to get all tables with number of rows in each table in a single shot.

thanks in advance

Arnav
Even you learn 1%, Learn it with 100% confidence.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-29 : 05:20:49
you need to create a cursor based script for looping through INFORMATION_SCHEMA.TABLES catalog view and then use dynamic sql for getting counts from each table.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gwilson67
Starting Member

42 Posts

Posted - 2011-08-29 : 00:53:24
Hi, here's a query from my code repository that I'll share with you. it doesn't need a cursor.

select st.name, si.rows from sys.tables st
inner join sysindexes si on st.object_id=si.id
where si.indid<2



Greg
http://www.freewebstore.org/tsqlcoderepository
Powerful tool for SQL Server development
Go to Top of Page
   

- Advertisement -