Find number of columns in Teradata database

Query returns basic statistics of numbers of columns in a database.

Query

SELECT  COUNT(*) AS Columns,
        COUNT(DISTINCT C.DatabaseName || '.' || C.TableName) AS Tables,
        1.00*Count(*)/COUNT(DISTINCT C.DatabaseName || '.' || C.TableName)
            AS AvgColumnCount
FROM    DBC.ColumnsV C
JOIN    DBC.TablesV T
ON      C.TableName = T.TableName
AND     C.DatabaseName = T.DatabaseName
AND     T.TableKind = 'T'
WHERE   C.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');

Columns

  • Columns - total number of columns
  • Tables - number of tables
  • AvgColumnCount - average number of columns in a table

Rows

  • Query returns just one row

Sample results

0
There are no comments. Click here to write the first comment.