Link to home
Start Free TrialLog in
Avatar of Axter
AxterFlag for United States of America

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of ghp7000
ghp7000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Axter

ASKER

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?
Avatar of ghp7000
ghp7000

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?
Avatar of Axter

ASKER

>>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.
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
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;

    }