AAA_king
AAA_king

Reputation: 91

How to get table name from column in DB2?

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.

Upvotes: 7

Views: 61083

Answers (4)

Keenan Stewart
Keenan Stewart

Reputation: 634

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.

Upvotes: 0

Wildcat Matt
Wildcat Matt

Reputation: 398

For DB2/AS400 users:

SELECT TABLE_SCHEMA, TABLE_NAME 
    FROM QSYS2.SYSCOLUMNS 
    WHERE upper(column_name) = upper('[column_name]')

Upvotes: 6

Peter Miehle
Peter Miehle

Reputation: 6070

SELECT tabname
    FROM syscat.columns
    WHERE colname = 'mycol'

Upvotes: 6

boes
boes

Reputation: 2855

select TBNAME
    from sysibm.syscolumns
    where NAME = '<column name>'

Upvotes: 14

Related Questions