List columns by name length in Teradata database

This query returns columns in a database sorted by their name length.

Query

SELECT  C.ColumnName,
        LENGTH(ColumnName) as ColumnNameLength,
        C.DatabaseName,
        C.TableName
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')
ORDER BY    LENGTH(ColumnName) DESC;

Columns

  • ColumnName - column name
  • ColumnNameLength - column name length
  • DatabaseName -database name
  • table_name - column's table name

Rows

  • One row represents one column of each table in a database
  • Scope of rows: each column that exists in a database
  • Ordered by length descending - from longest to shortest

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.