20

大家好,我正在学习 DB2,想知道创建表后如何查看表的特征。

类似于 MySQL 中的 EXPLAIN TABLE 命令。

谢谢你。

4

11 回答 11

14

除此之外DESCRIBE TABLE,您还可以使用以下命令

DESCRIBE INDEXES FOR TABLE *tablename* SHOW DETAIL 

获取有关表索引的信息。

可以从 db2look 实用程序获得有关 Db2 for Linux, UNIX, and Windows 上表的最全面的详细信息,您可以从远程客户端或直接在 Db2 服务器上以本地用户身份运行该实用程序。该工具生成模拟表及其统计数据所需的 DDL 和其他信息。Db2 11.5 中 db2look 的文档在这里

以下db2look命令将连接到 SALESDB 数据库并获取重新创建 ORDERS 表所需的 DDL 语句

db2look -d SALESDB -e -t ORDERS
于 2009-06-17T23:44:27.187 回答
11

我知道这是一个古老的问题,但这将完成这项工作。

SELECT colname, typename, length, scale, default, nulls
  FROM syscat.columns
 WHERE tabname = '<table name>'
   AND tabschema = '<schema name>'
 ORDER BY colno
于 2012-07-30T18:12:30.293 回答
6

db2look -d <db_name> -e -z <schema_name> -t <table_name> -i <user_name> -w <password> > <file_name>.sql

欲了解更多信息,请参阅以下内容:

    db2look [-h]

    -d: Database Name: This must be specified

    -e: Extract DDL file needed to duplicate database
   -xs: Export XSR objects and generate a script containing DDL statements
 -xdir: Path name: the directory in which XSR objects will be placed
    -u: Creator ID: If -u and -a are both not specified then $USER will be used
    -z: Schema name: If -z and -a are both specified then -z will be ignored
    -t: Generate statistics for the specified tables
   -tw: Generate DDLs for tables whose names match the pattern criteria (wildcard characters) of the table name
   -ap: Generate AUDIT USING Statements
  -wlm: Generate WLM specific DDL Statements
  -mod: Generate DDL statements for Module
  -cor: Generate DDL with CREATE OR REPLACE clause
 -wrap: Generates obfuscated versions of DDL statements
    -h: More detailed help message
    -o: Redirects the output to the given file name
    -a: Generate statistics for all creators
    -m: Run the db2look utility in mimic mode
        -c: Do not generate COMMIT statements for mimic
        -r: Do not generate RUNSTATS statements for mimic
    -l: Generate Database Layout: Database partition groups, Bufferpools and Tablespaces
    -x: Generate Authorization statements DDL excluding the original definer of the object
   -xd: Generate Authorization statements DDL including the original definer of the object
    -f: Extract configuration parameters and environment variables
   -td: Specifies x to be statement delimiter (default is semicolon(;))
    -i: User ID to log on to the server where the database resides
    -w: Password to log on to the server where the database resides
于 2014-10-03T12:48:46.713 回答
5

描述表的语法

db2 describe table <tablename>

或所有表格详细信息

select * from syscat.tables

或所有表格详细信息

 select * from sysibm.tables
于 2009-02-18T07:40:03.007 回答
4

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.

于 2009-02-14T07:25:26.333 回答
2

右键单击 DB2 Control Center 中的表并选择 Generate DDL... 这将为您提供所需的一切以及更多。

于 2013-04-04T16:43:29.937 回答
1

尝试以下操作:

DESCRIBE SELECT * FROM TABLE_name
于 2013-04-16T18:30:46.420 回答
1

您可以使用以下命令查看 DB 的完整特征

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

您可以使用以下命令查看 Schema 的完整特征

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

您可以使用以下命令查看表格的完整特征

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

您也可以访问以下链接了解更多详情。 https://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=%2Fcom.ibm.db2.udb.admin.doc%2Fdoc%2Fr0002051.htm

于 2013-12-30T05:50:26.523 回答
1

我刚刚遇到这个查询来描述winsql中的一个表

select NAME,TBNAME,COLTYPE,LENGTH,REMARKS,SCALE from sysibm.syscolumns
where tbcreator = 'Schema_name' and tbname='Table_name' ;
于 2016-02-15T04:47:05.830 回答
0

描述表语法

describe table schemaName.TableName
于 2011-12-05T07:03:01.243 回答
0

DB2 版本 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;
于 2017-07-03T03:28:54.033 回答