Reputation: 8796
I am using DB2 where I have a table which has 300 columns. How can I search for the column name which contains a specific string? I know the table name and the string. Is that possible in DB2?
Upvotes: 0
Views: 85
Reputation: 17118
Db2 stores its metadata in the so-called catalog. You can find the roadmap to the catalog views in the Db2 Knowledge Center. The view SYCAT.COLUMNS holds information about the columns for the tables in a database.
Without testing, you could write a query like this to search for the string:
select colname
from syscat.tables
where tabname=YOURTABLE and tabschema=YOURTABLESCHEMA and colname LIKE '%YOURSTRING%'
This would search in that table for the column names for YOURTABLESCHEMA.YOURTABLE and use the LIKE expression to search for a column name that contains YOURSTRING.
Upvotes: 1