How to view the table structure in DB2 database
php example for iSeries (as400) db2, yes this worked!
$i5 = db2_connect($database, $user, $password, array("i5_lib"=>"qsys2"));
$querydesc = "select * from qsys2.syscolumns where table_schema = '".$library."' and table_name = '".$table_name."' ";
$result = db2_exec($i5, $querydesc);
also if you just want to list all tables with their descriptions
$query = "select TABLE_NAME, TABLE_TEXT from systables where table_schema = '$library' ";
$result = db2_exec($i5, $query);
FOR TABLE DESCRIPTION IN IBM DB2 10.7 VERSION I TRIED THIS AND IT WORKED FINE
SELECT NAME,COLTYPE,NULLS,LONGLENGTH FROM SYSIBM.SYSCOLUMNS where TBcreator =SCHEMANAME and TBNAME =TABLENAME;
The OP doesn't mention if this is DB2/400 being discussed, but I found that the only way I could get the table structure including the column name descriptions was to use DSPFFD.
DSPFFD FILE(TBNAME) OUTPUT(*OUTFILE) OUTFILE(SOMELIB/TBDESC)
This puts the description of TBNAME in a table called TBDESC in the SOMELIB library. You can then query that with:
select * from SOMELIB/TBDESC
if you're using Aqua Data studio, simply write select * from table_name and instead of pressing execute,, press ctrl +D .
You shall be able to see the description for the table
Generally it's easiest to use DESCRIBE.
DESCRIBE TABLE MYSCHEMA.TABLE
or
DESCRIBE INDEXES FOR MYSCHEMA.TABLE SHOW DETAIL
etc.
See the documentation: DESCRIBE command
You can Get the table meta data using this query
SELECT * FROM SYSIBM.COLUMNS WHERE TABLE_NAME = 'ASTPCLTEXT';