我正在使用DB2数据库.什么是合适的SQL查询来查明表或表列表中是否存在列?
例如
if "column_name" is found in "table name" or [list of table names]
return true or the name of tables that have that column.
Run Code Online (Sandbox Code Playgroud)
非常感谢.
在DB2 z/OS 9.1和LUW 9.7上测试:
SELECT STRIP(TBCREATOR) || '.' || STRIP(TBNAME)
FROM SYSIBM.SYSCOLUMNS
WHERE NAME = 'your_col'
AND TBNAME IN ('list', 'of', 'tables')
Run Code Online (Sandbox Code Playgroud)
如果您只想要特定模式的结果,则可以添加AND TBCREATOR = 'your_schema'到查询的末尾.
SELECT TABNAME
FROM SYSCAT.COLUMNS
WHERE
TABNAME IN ('table name 1', 'table name 2') AND
COLNAME = 'column_name';
Run Code Online (Sandbox Code Playgroud)