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.
Asked
Active
Viewed 5.7k times
7
-
It is possible that multiple tables have a column with that name. Especially if the column name is for example "ID" or "LAST_UPDATED" – crowne Sep 01 '11 at 17:59
-
1@crowne - Check the question please I have already mentioned table/tables. – AAA_king Sep 01 '11 at 19:13
4 Answers
14
select TBNAME
from sysibm.syscolumns
where NAME = '<column name>'

Vitaliy Ulantikov
- 10,157
- 3
- 61
- 54

boes
- 2,835
- 2
- 23
- 28
6
SELECT tabname
FROM syscat.columns
WHERE colname = 'mycol'

Vitaliy Ulantikov
- 10,157
- 3
- 61
- 54

Peter Miehle
- 5,984
- 2
- 38
- 55
-
2Object names default to all upper case in DB2, but in case someone is deliberately using mixed-case names, consider using WHERE UPPER(colname) = UPPER('somecolumnname') – Fred Sobotka Sep 07 '11 at 17:17
-
You should even consider not using UPPER in the right part of the condition, for performance purposes `WHERE UPPER(colname) = "SOMECOLUMNNAME` – Kilazur Dec 12 '14 at 10:15
5
For DB2/AS400 users:
SELECT TABLE_SCHEMA, TABLE_NAME
FROM QSYS2.SYSCOLUMNS
WHERE upper(column_name) = upper('[column_name]')

Wildcat Matt
- 388
- 4
- 13
0
If you are using Visual Studio Server Explorer, I found using the following worked the best:
SELECT TABNAME
FROM SYSCAT.COLUMNS
WHERE COLNAME = 'NASR_DESC'
Visual Studio still formatted it, but the formatting inserted by Visual Studio still worked.
Hope this helps someone searching for a known column name in their IBM DB2 database using Visual Studio Server Explorer.

brasofilo
- 25,496
- 15
- 91
- 179

Keenan Stewart
- 594
- 6
- 9