How to view DB2 Table structure

后端 未结 19 2307
深忆病人
深忆病人 2020-12-24 00:59

How to view the table structure in DB2 database

相关标签:
19条回答
  • 2020-12-24 01:22

    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);
    
    0 讨论(0)
  • 2020-12-24 01:25

    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;
    
    0 讨论(0)
  • 2020-12-24 01:25

    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

    0 讨论(0)
  • 2020-12-24 01:26

    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

    0 讨论(0)
  • 2020-12-24 01:27

    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

    0 讨论(0)
  • 2020-12-24 01:28

    You can Get the table meta data using this query

    SELECT * FROM SYSIBM.COLUMNS WHERE TABLE_NAME = 'ASTPCLTEXT';
    
    0 讨论(0)
提交回复
热议问题