How to view the table structure in DB2 database
1.use db2 describe table
db2 describe table tabschema.tabname
2.use db2 describe output
db2 "describe select * from tabschema.tabname"
3.use db2look utility
db2look -d dbname -e -t tabname
4.find rows in db2 syscat
db2 "Select * from syscat.columns wher tabname='' and tabschema =''"
Control Center already got the feature of that. It's just below the table list.
I am using Aquadata Studio 12.0.23, which is several versions short of the newest. So your experience may be better than mine. I found that the best way to get an overview was to use the ERD generator. It took a couple of hours, since normalization was not a concept used in the design of this database almost 30 years ago. I was able to get definitions for all of the objects in a few hours, with a file for each.
I am running DB2/LINUXX8664 10.5.3 and describe select * from schema_name.table_name
works for me.
However, describe table schema_name.table_name
fails with this error:
SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a
query is an empty table. SQLSTATE=02000
How to view the table structure in db2 database
Open db2
command window, connect to db2 with following command.
> db2 connect to DATABASE_NAME USER USERNAME USING PASSWORD
Once you connected successfully, issue the following command to view the table structure.
> db2 "describe select * from SCHEMA_NAME.TABLE_NAME"
The above command will display db2 table structure in tabular format.
Note: Tested on DB2 Client 9.7.11
drop view lawmod9t.vdesc
create view lawmod9t.vDesc as select
upper(t.table_cat) as Catalog,
upper(t.table_schem) as Schema,
upper(t.table_name) as table,
t.table_text as tableDesc,
c.system_column_name as colname_short,
c.column_name as colname_long,
c.column_text as coldesc,
c.Type_Name as type,
c.column_Size as size
from sysibm.SQLColumns c
inner join sysibm.sqltables t
on c.table_schem = t.table_schem
and c.table_name = t.table_name
select * from vdesc where table = 'YPPPOPL'