SQL 如何从 DB2 中的列中获取表名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7274151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get table name from column in DB2?
提问by AAA_king
I need the db2 sql query to find the table/tables from column name. I have the column name but don't have table name which this column belongs to.
我需要 db2 sql 查询从列名中查找表/表。我有列名,但没有该列所属的表名。
回答by boes
select TBNAME
from sysibm.syscolumns
where NAME = '<column name>'
回答by Peter Miehle
SELECT tabname
FROM syscat.columns
WHERE colname = 'mycol'
回答by Wildcat Matt
For DB2/AS400 users:
对于 DB2/AS400 用户:
SELECT TABLE_SCHEMA, TABLE_NAME
FROM QSYS2.SYSCOLUMNS
WHERE upper(column_name) = upper('[column_name]')
回答by Keenan Stewart
If you are using Visual Studio Server Explorer, I found using the following worked the best:
如果您使用的是 Visual Studio Server Explorer,我发现使用以下方法效果最好:
SELECT TABNAME
FROM SYSCAT.COLUMNS
WHERE COLNAME = 'NASR_DESC'
Visual Studio still formatted it, but the formatting inserted by Visual Studio still worked.
Visual Studio 仍然对其进行格式化,但 Visual Studio 插入的格式仍然有效。
Hope this helps someone searching for a known column name in their IBM DB2 database using Visual Studio Server Explorer.
希望这有助于有人使用 Visual Studio Server Explorer 在他们的 IBM DB2 数据库中搜索已知的列名。