On DB2 for i, Search for Column, return table names in list form

Jay Carr picture Jay Carr · Dec 6, 2012 · Viewed 12.3k times · Source

I'm still a bit of a noob, so pardon if this question is a bit obvious. I did search for an answer but either couldn't understand how the answers I found applied, or simply couldn't find an answer.

I have a massive database housed on a DB2 for i server which I'm accessing using SQL through SQLExplorer (based on Squirrel SQL). The tables are very poorly documented and the first order of business is figuring out how to find my way around.

I want to write a simple query that does this:

1) Allows me to search the entire database looking for tables that include a column called "Remarks" (which contains field descriptions).

2) I then want it to search that column for a keyword.

3) I want a table returned that includes the names of the tables that include that keyword (just the name, I can look up the table alphabetically later and look inside if I need to.)

I need this search to be super lightweight, and I'm hoping the concept I describe will achieve that. Anything that eats up a lot of resources will likely anger the sys admin for the server.

Just to show I have tried (and that I am a complete noob), here's what I've got so far.

SELECT *
FROM <dbname>
WHERE Remarks LIKE '<keyword>'

Feel free to mock, I told you I'm an idiot :-).

Any help? Perhaps at least a push in the right direction?

PS - I can't seem to find a search function in SQLExplorer, if someone knows if I can perhaps use a simple search or filter to accomplish this same goal...that would be great.

Answer

James Allman picture James Allman · Dec 6, 2012

You can query the system catalog to identify the tables:

SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME 
FROM QSYS2.SYSCOLUMNS WHERE UPPER(DBILFL) = 'REMARKS'

And then query each table individually:

SELECT * FROM TABLE_SCHEMA.TABLE_NAME WHERE Remarks LIKE '%<keyword>%'

See the LIKE predicate for details of the pattern expression.