Im using a DB2 Database. What would be a suitable SQL query to find out if a column is exists in a table or list of tables?
e.g
if "column_name" is found in "table name" or [list of table names]
return true or the name of tables that have that column.
Many thanks.
Tested on DB2 z/OS 9.1 and LUW 9.7:
SELECT STRIP(TBCREATOR) || '.' || STRIP(TBNAME)
FROM SYSIBM.SYSCOLUMNS
WHERE NAME = 'your_col'
AND TBNAME IN ('list', 'of', 'tables')
If you only want results from a specific schema you might add AND TBCREATOR = 'your_schema'
to the end of the query.
Use SYSCAT.COLUMNS
catalog view:
SELECT TABNAME
FROM SYSCAT.COLUMNS
WHERE
TABNAME IN ('table name 1', 'table name 2') AND
COLNAME = 'column_name';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With