4

I have 2-3 different column names that I want to look up in the entire DB and list out all tables which have those columns. Any easy query?

I have seen solution for MySQL, which won't work here because TD as far as I know don't have schemes, but instead I found this.

And tried this code:

SELECT TableName
FROM DBC.COLUMNS
WHERE DatabaseName = 'DB_NAME' and
ColumnName in ('col1', 'col2')

But surely subquery must be used to get TableName, because DBC.COLUMNS doesn't have that field. Any further ideas?

Community
  • 1
  • 1
Rocketq
  • 4,776
  • 17
  • 70
  • 119
  • 1
    `DBC.Columns` seems to be what you are looking for: http://www.info.teradata.com/HTMLPubs/DB_TTU_14_00/index.html#page/Database_Management/B035_1092_111A/Views_Reference.015.134.html#ww25068441 – a_horse_with_no_name Feb 04 '15 at 10:54

2 Answers2

9

You are looking for this:

SELECT tablename
FROM dbc.columnsV
WHERE ColumnName in ('col1', 'col2')
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709
3

This query works with me :

SELECT  DatabaseName,
        TableName,
        CreateTimeStamp,
        LastAlterTimeStamp
FROM    DBC.TablesV
WHERE   TableKind = 'T'
and     DatabaseName = 'YOUR_SCHEMA'
ORDER BY    TableName;