How to view DB2 Table structure

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

How to view the table structure in DB2 database

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

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

    In DB2, enter on db2 command prompt.

      db2  =>  describe  table MyTableName
    
    0 讨论(0)
  • 2020-12-24 01:35

    I got the answer from the sysibm.syscolumns

    Select distinct(name), ColType, Length from Sysibm.syscolumns where tbname = 'employee';
    
    0 讨论(0)
  • 2020-12-24 01:36

    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 :)

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

    Follow this simple steps:

    1. Select the Browsers window.
    2. Extract (expand) it.
    3. Select and extract (expand) the table list.
    4. Select the required table and extract (expand) it.
    5. On double click the code option, it opens the table structure.
    0 讨论(0)
  • 2020-12-24 01:37

    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

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