简体   繁体   English

如何在数据库 Teradata 中查找具有特定列名的所有表?

[英]How to find all the tables in database Teradata with specific column names in them?

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.我有 2-3 个不同的列名,我想在整个数据库中查找并列出所有包含这些列的表。 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 .我已经看到了 MySQL 的解决方案,它在这里不起作用,因为据我所知 TD 没有方案,但我找到了这个

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.但是肯定必须使用子查询来获取 TableName,因为 DBC.COLUMNS 没有该字段。 Any further ideas?任何进一步的想法?

You are looking for this:你正在寻找这个:

SELECT tablename
FROM dbc.columnsV
WHERE ColumnName in ('col1', 'col2')

This query works with me :此查询适用于我:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM