Sathish Kumar
Sathish Kumar

Reputation: 2536

How to find schema of a table in DB2?

I am new to DB2 and I created two tables 'PROJECT_ADAPTERS' and 'PROJECT_APPLICATIONS' under database 'WLADMIN'

I am able to see the tables using 'syscat.tables' as shown below

[db2inst1@574 ~]$ db2 "select TABNAME from syscat.tables" | grep PROJ
PROJECT_ADAPTERS                                                           
PROJECT_APPLICATIONS                                                          

However I am not sure, to which schema it belongs to ?

I tried writing a little script which loops through all the 'schemas'

schemaname=$(db2 -v select schemaname from syscat.schemata)

for each_schema in $schemaname
do
    db2 list tables for schema $each_schema | grep PROJ
done

However, my tables 'PROJECT_ADAPTERS' and 'PROJECT_APPLICATIONS' are not showing up against any schema

What am I doing wrong (or) where else should I look out for ?

Please help me to resolve this issue

Upvotes: 2

Views: 16820

Answers (1)

data_henrik
data_henrik

Reputation: 17118

Most tables have multiple columns, you can use them... ;)

select tabname,tabschema from syscat.tables where tabname like 'PROJECT%' should show your tables and the schema name.

The catalog SYSCAT.TABLES is fully documented.

Upvotes: 3

Related Questions