Q
Problem solve Get help with specific problems with your technologies, process and projects.

Number of rows in multiple tables

I need a query which will give the tablename and the count of the number of rows. Is it possible?

I need a query which will give the tablename and the count of the number of rows. Is it possible?

Yes, it's fairly straightforward.

select 'Customers' as tablename
     , count(*) as row_count
  from Customers
union all
select 'Orders' as tablename
     , count(*) as row_count
  from Orders
union all
select 'Products' as tablename
     , count(*) as row_count
  from Products
union all
...

If you need to run this for all tables in your database, you can generate the list of tables from the INFORMATION_SCHEMA.TABLES view:

select table_name
  from information_schema.tables
 where table_schema = 'mydatabase'

Then you can use the result set of this query along with a text editor to generate the first query.

This was last published in August 2007

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close