I have a set of tables in Oracle and I would like to identify the table that contains the maximum number of rows.
So if, A has 200 rows, B has 345 rows and C has 120 rows I want to be able to identify table B.
Is there a simple query I can run to achieve this?
Edit: There are 100 + tables so I am looking for something generic.
3 bytes are used to store the page number a maximum of 16,777,215 pages can be used in one table. 1 byte is used to store the slot number, a single page can have at most 255 slots/rows. The maximum number of rows in a table or fragment is 4,278,189,825.
select segment_name,segment_type, sum(bytes/1024/1024/1024) GB from dba_segments where segment_name='&Your_Table_Name' group by segment_name,segment_type; Storage.
Given that you said you were using Oracle I would just query the meta-data.
select table_name, max(num_rows) from all_tables where table_name in ('A', 'B', 'C');
Just saw your edit. Just run the above without the where clause and it will return the largest table in the database. Only problem may be that you might get a SYS$ table or something. Alternately if you are just doing this for your own knowledge just do
select table_name, num_rows from all_tables order by num_rows;
and you'll see what the biggest are.
The table in your schema that has max rows:
with data as
(
select table_name,
to_number(extractvalue(xmltype(
dbms_xmlgen.getxml (
' select count(*) c from ' || table_name)),
'/ROWSET/ROW/C')) countrows
from user_tables
)
select table_name, countrows
from data
where countrows = (select max(countrows)
from data);
dbms_xmlgen.getxml(' select .... ') is extremely flexible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With