Number of tables by the number of rows in Db2 database

If you want to get an overview of the number of rows the tables contain in your database, one way to count them is by intervals of rows. This query returns the number of tables grouped by the number of rows at predefined intervals.

Query

select row_count,
       count(table_name) as tables
from (
      select tabschema || '.'|| tabname as table_name, 
             case when card > 1000000000 then '1b rows and more'
                  when card > 1000000 then '1m - 1b rows'
                  when card > 1000 then '1k - 1m rows'
                  when card > 100 then '100 - 1k rows'
                  when card > 10 then '10 - 100 rows'
                  else  '0 - 10 rows' end as row_count
      from syscat.tables
      where tabschema not like 'SYS%'
) as tables_rows_interval
group by row_count
order by row_count

Columns

  • row_count - predefined row count intervals:
    • 0 - 10 rows
    • 10 - 100 rows
    • 100 - 1k rows
    • 1k - 1m rows
    • 1m - 1b rows
    • 1b rows and more
  • tables - number of tables whose row count falls in that interval

Rows

  • One row: represents one interval
  • Scope of rows: all row count intervals that appear in the database (schema)
  • Ordered by: from the smallest table row count to the largest

Sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.