IBM Support

Row count of tables in database

Question & Answer


Question

How do I get a row count for all tables in a database?

Answer

The following SQL will provide a row count for all tables in a database. Note, however, that the count is only as accurate as the last generate statsistics run.

    select      relname,
                case
                  when reltuples < 0 then ((2^32) * relrefs) + ((2^32) + reltuples )
                  else ((2^32) * relrefs) + ( reltuples )
                end AS "Statistics Rowcount"
    from       _t_class,
               _t_object
    where      _t_object.objid=_t_class.oid and
               _t_object.objclass=4905 -- display only tables
[{"Product":{"code":"SSULQD","label":"IBM PureData System"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":null,"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"1.0.0","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Historical Number

NZ345051

Document Information

More support for:
IBM PureData System

Software version:
1.0.0

Document number:
465483

Modified date:
17 October 2019

UID

swg21573512