How to view the table structure in DB2 database
to get all tables: (You may want to restrict schema to your schema)
select * from syscat.tables
to get all columns: (where tabname = your_tabname)
select * from syscat.columns
In DB2, enter on db2 command prompt.
db2 => describe table MyTableName
I got the answer from the sysibm.syscolumns
Select distinct(name), ColType, Length from Sysibm.syscolumns where tbname = 'employee';
The easiest way as many have mentioned already is to do a DESCRIBE TABLE
However you can also get some the same + additional information from
db2> SELECT * SYSCAT.TABLES
db2> SELECT * FROM SYSCAT.COLUMNS
I usually use SYSCAT.COLUMNS to find the related tables in the database where I already know the column name :)
Another good way if you want to get the DDL of a particular table or the whole database is to use the db2look
# db2look -d *dbname* -t *tablename* > tablestructure.out
This will generate the ".out" file for you which will contain the particular table's DDL script.
# db2look -d *dbname* -e > dbstructure.out
This will generate the entire database's DDL as a single script file, this is usually used to replicate the database, "-e" is to indicate that one wants to export DDL suitable recreate exact same setup in a new database.
Hope this can help someone looking for such answers :)
Follow this simple steps:
Use the below to check the table description for a single table
DESCRIBE TABLE Schema Name.Table Name
join the below tables to check the table description for a multiple tables, join with the table id syscat.tables and syscat.columns
You can also check the details of indexes on the table using the below command describe indexes for table . show detail