In DB2 Display a table's definition

后端 未结 11 1063
长情又很酷
长情又很酷 2021-02-04 03:35

Hello everybody I am learning DB2 and would like to know how to see a table\'s characteristics after I create one.

Similar to the EXPLAIN TABLE command in MySQL.

<
相关标签:
11条回答
  • 2021-02-04 03:53

    Describe table syntax

    describe table schemaName.TableName
    
    0 讨论(0)
  • 2021-02-04 03:57

    DB2 Version 11.0

    Columns:
    --------
    SELECT NAME,COLTYPE,NULLS,LENGTH,SCALE,DEFAULT,DEFAULTVALUE FROM SYSIBM.SYSCOLUMNS where TBcreator ='ME' and TBNAME ='MY_TABLE' ORDER BY COLNO;
    
    Indexes:
    --------
    SELECT P.SPACE, K.IXNAME, I.UNIQUERULE, I.CLUSTERING, K.COLNAME, K.COLNO, K.ORDERING
    FROM SYSIBM.SYSINDEXES I
        JOIN SYSIBM.SYSINDEXPART P
            ON I.NAME = P.IXNAME
            AND I.CREATOR = P.IXCREATOR
        JOIN SYSIBM.SYSKEYS K
            ON P.IXNAME = K.IXNAME
            AND P.IXCREATOR = K.IXCREATOR
    WHERE I.TBcreator ='ME' and I.TBNAME ='MY_TABLE'
    ORDER BY K.IXNAME, K.COLSEQ;
    
    0 讨论(0)
  • 2021-02-04 04:02

    In addition to DESCRIBE TABLE, you can use the command below

    DESCRIBE INDEXES FOR TABLE *tablename* SHOW DETAIL 
    

    to get information about the table's indexes.

    The most comprehensive detail about a table on Db2 for Linux, UNIX, and Windows can be obtained from the db2look utility, which you can run from a remote client or directly on the Db2 server as a local user. The tool produces the DDL and other information necessary to mimic tables and their statistical data. The docs for db2look in Db2 11.5 are here.

    The following db2look command will connect to the SALESDB database and obtain the DDL statements necessary to recreate the ORDERS table

    db2look -d SALESDB -e -t ORDERS
    
    0 讨论(0)
  • 2021-02-04 04:03

    All that metadata is held in the DB2 catalog tables in the SYSIBM 'schema'. It varies for the DB2/z mainframe product and the DB2/LUW distributed product but they're coming closer and closer with each release.

    IBM conveniently place all their manuals up on the publib site for the world to access. My area of expertise, DB2/z, has the pages you want here.

    There are a number of tables there that you'll need to reference:

    SYSTABLES        for table information.
    SYSINDEXES    \
    SYSINDEXPART   + for index information.
    SYSKEYS       /
    SYSCOLUMNS       for column information.
    

    The list of all information centers is here which should point you to the DB2/LUW version if that's your area of interest.

    0 讨论(0)
  • 2021-02-04 04:06

    you can use the below command to see the complete characteristics of DB

    db2look -d <DB NAme>-u walid -e -o
    

    you can use the below command to see the complete characteristics of Schema

     db2look -d <DB NAme> -u walid -z <Schema Name> -e -o
    

    you can use the below command to see the complete characteristics of table

    db2look -d <DB NAme> -u walid -z <Schema Name> -t <Table Name>-e -o
    

    you can also visit the below link for more details. https://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=%2Fcom.ibm.db2.udb.admin.doc%2Fdoc%2Fr0002051.htm

    0 讨论(0)
提交回复
热议问题