List table default values in Teradata database

This query returns list of all columns with a default value in a specific table.

Query

SELECT  COL.DatabaseName,
        COL.TableName,
        COL.ColumnName,
        COL.DefaultValue
FROM    DBC.ColumnsV COL
JOIN    DBC.Tablesv TAB
ON      TAB.DatabaseName = COL.DatabaseName
AND     TAB.TableName = COL.TableName
AND     TAB.TableKind = 'T'
WHERE   COL.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')
AND     COL.DefaultValue IS NOT NULL
ORDER BY    COL.DatabaseName,
            COL.TableName,
            COL.ColumnName;

Columns

  • DatabaseName - database name
  • TableName - table name
  • ColumnName - column name
  • DefaultValue - column's default value

Rows

  • One row represents one column
  • Scope of rows: columns with a default value in a specified table
  • Ordered by database name, table name, column name

Sample results