How to see the schema of a db2 table (file)

强颜欢笑 提交于 2020-01-14 07:47:08

问题


As in subject... is there a way of looking at an empty table schema without inserting any rows and issuing a SELECT?


回答1:


Are you looking for DESCRIBE?

db2 describe table user1.department

Table: USER1.DEPARTMENT

Column             Type        Type
name               schema      name               Length   Scale    Nulls
------------------ ----------- ------------------ -------- -------- --------
AREA               SYSIBM      SMALLINT                  2        0 No
DEPT               SYSIBM      CHARACTER                 3        0 No
DEPTNAME           SYSIBM      CHARACTER                20        0 Yes



回答2:


SELECT *                
FROM SYSIBM.SYSCOLUMNS  
WHERE                   
TBNAME    = 'tablename'; 



回答3:


For DB2 AS/400 (V5R4 here) I used the following queries to examine for database / table / column metadata:

SELECT * FROM SYSIBM.TABLES -- Provides all tables

SELECT * FROM SYSIBM.VIEWS -- Provides all views and their source (!!) definition

SELECT * FROM SYSIBM.COLUMNS -- Provides all columns, their data types & sizes, default values, etc.

SELECT * FROM SYSIBM.SQLPRIMARYKEYS -- Provides a list of primary keys and their order




回答4:


Looking at your other question, DESCRIBE may not work. I believe there is a system table that stores all of the field information.

Perhaps this will help you out. A bit more coding but far more accurate.



来源:https://stackoverflow.com/questions/153769/how-to-see-the-schema-of-a-db2-table-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!