I need a query which will give the tablename and the count of the number of rows. Is it possible?
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
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.
Dig Deeper on Oracle and SQL
Related Q&A from Rudy Limeback
Read an example of an SQL case expression from our SQL expert Rudy Limeback.continue reading
Read about the Mimer Validator, a tool used to verify your SQL code, in this tip from SQL expert Rudy Limeback.continue reading
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clausecontinue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.