How to view DB2 Table structure

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

How to view the table structure in DB2 database

19条回答
  •  無奈伤痛
    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 :)

提交回复
热议问题