Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB2 Query to retrieve all table names for a given schema

I'm just looking for a simple query to select all the table names for a given schema.

For example, our DB has over 100 tables and I need to find any table that contains the sub-string “CUR”. I can use the like command once I have all the tables.

like image 240
Ben Avatar asked Aug 27 '10 12:08

Ben


People also ask

How do I list all tables in a specific schema?

The easiest way to find all tables in SQL is to query the INFORMATION_SCHEMA views. You do this by specifying the information schema, then the “tables” view. Here's an example. SELECT table_name, table_schema, table_type FROM information_schema.

How do I find the schema name for a table in DB2?

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


1 Answers

select * from sysibm.systables where owner = 'SCHEMA' and name like '%CUR%' and type = 'T'; 

This will give you all the tables with CUR in them in the SCHEMA schema.

See here for more details on the SYSIBM.SYSTABLES table. If you have a look at the navigation pane on the left, you can get all sorts of wonderful DB2 metatdata.

Note that this link is for the mainframe DB2/z. DB2/LUW (the Linux/UNIX/Windows one) has slightly different columns. For that, I believe you want the CREATOR column.

In any case, you should examine the IBM docs for your specific variant. The table name almost certainly won't change however, so just look up SYSIBM.SYSTABLES for the details.

like image 189
paxdiablo Avatar answered Oct 11 '22 09:10

paxdiablo