?
Solved

List all tables in a database

Posted on 2005-03-17
6
Medium Priority
?
79,883 Views
Last Modified: 2012-05-05
What is the SQL command to list all tables in a database?
What is the SQL command to list all columns in a table?
0
Comment
Question by:Axter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Accepted Solution

by:
ghp7000 earned 2000 total points
ID: 13565499
from db2 command prompt:
db2 list tables for schema <schema name>
or
all table information is stored in syscat.tables view
db2 select * from syscat.tables where tabschema=<schema name> or simply
db2 select * from syscat.tables order by tabschema, tabname

similarly, allcolumn information is stored in syscat.columns
db2 select * from syscat.columns where tabname=<table name>



0
 
LVL 30

Author Comment

by:Axter
ID: 13565608
In doing some keyword search, I found the following command:
select * from SYSIBM.SYSTABLES

The above command seem to also pull all the table names.

What is the difference between SYSIBM.SYSTABLES and SYSCAT.TABLES?

Are there other database types that can use SYSCAT.TABLES?

I'm trying to setup my code so that it can work with IBM UDB, Sybase, and Btrieve.

Do you know if SYSCAT.TABLES will work with Sybase or Btrieve?
0
 
LVL 13

Expert Comment

by:ghp7000
ID: 13566265
the syscat tables are simply the views which are based on the sysibm tables.
DB2 LIST TABLES FOR SCHEMA SYSCAT will show you which views are available, they cover the entire range of the database, every object, package, plan, dependancy, relation can be found in these views.

When you say will the sycat tables work with sybase or Btrieve, what exactly do you mean?
0
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
LVL 30

Author Comment

by:Axter
ID: 13566312
>>When you say will the sycat tables work with sybase or Btrieve, what exactly do you mean?

I have a program that can connect to these databases using ODBC.
With ODBC, I can issue a SQL command.

I'm trying to setup my program so I can use the same SQL command for all three database types.
0
 
LVL 13

Expert Comment

by:ghp7000
ID: 13566552
there is no problem for your odbc connection to query the syscat tables, these tables do not have any built security mechanism, they are treated llike any other table
0
 

Expert Comment

by:RdeLange
ID: 14385662
to list all tables use
   public static String[] getDatabases(){
          databasess = new String[2000];
          int teller = 1;
          try{
          String qry = "Select SYSTEM_TABLE_SCHEMA, SYSTEM_TABLE_NAME, ROW_LENGTH";
          qry = qry +  " from QSYS2.SYSTABLES where SYSTEM_TABLE_SCHEMA like 'VDR%'";
          print(qry);        
          //print(resultSet.toString());                            
                resultSet = statement.executeQuery(qry);
              while (resultSet.next()) {
                      String library = resultSet.getString("SYSTEM_TABLE_SCHEMA");
                      String table   = resultSet.getString("SYSTEM_TABLE_NAME");
                      int    records = resultSet.getInt("ROW_LENGTH");
                      System.out.println(library+" "+ table+" "+records);
                      databasess[teller] = library;
                      print("");
                      teller++;
                  }
            }      
        catch (SQLException cnfex) {dbError(cnfex,"ShowDatabases");}
            return databasess;

    }
0

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month12 days, 20 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question