Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 79950
  • Last Modified:

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?
0
Axter
Asked:
Axter
  • 3
  • 2
1 Solution
 
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
 
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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
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

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now