List all tables in a database

What is the SQL command to list all tables in a database?
What is the SQL command to list all columns in a table?
LVL 30
AxterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ghp7000Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AxterAuthor Commented:
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
ghp7000Commented:
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

AxterAuthor Commented:
>>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
ghp7000Commented:
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
RdeLangeCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.