Number of tables by the number of rows in Teradata 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  RowInterval,
        COUNT(*) AS Tables
FROM (
    SELECT  DatabaseName,
            TableName,
            CASE 
                WHEN RowCount > 1000000000 THEN '1b rows and more'
                WHEN RowCount > 1000000 THEN '1m - 1b rows'
                WHEN RowCount > 1000 THEN '1k - 1m rows'
                WHEN RowCount > 100 THEN '100 - 1k rows'
                WHEN RowCount > 10 THEN '10 - 100 rows'
                ELSE  '0 - 10 rows' END AS RowInterval,
            RowCount
    FROM    DBC.TableStatsV
    WHERE   IndexNumber = 1
    AND DataBaseName NOT IN ('All', 'Crashdumps', 'DBC', 'dbcmngr', 
        'Default', 'External_AP', 'EXTUSER', 'LockLogShredder', 'PUBLIC',
        'Sys_Calendar', 'SysAdmin', 'SYSBAR', 'SYSJDBC', 'SYSLIB', 
        'SystemFe', 'SYSUDTLIB', 'SYSUIF', 'TD_SERVER_DB',  'TDStats',
        'TD_SYSGPL', 'TD_SYSXML', 'TDMaps', 'TDPUSER', 'TDQCD',
        'tdwm',  'SQLJ', 'TD_SYSFNLIB',  'SYSSPATIAL')
) itv
GROUP BY RowInterval
ORDER BY MAX(RowCount);

Columns

  • RowInterval - 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
  • 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.