SQL DB2 表中列的描述
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/580735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Description of columns in a DB2 table
提问by
How can we know the description of every column in a table(DB2) through SQL?
我们如何通过SQL知道表(DB2)中每一列的描述?
My data base is DB2.
我的数据库是 DB2。
回答by Peter Miehle
select
tabname,
colname,
typename,
length,
scale,
default,
nulls,
identity,
generated,
remarks,
keyseq
from
syscat.columns
回答by Rwly
SELECT
TABLE_CAT,
TABLE_SCHEM,
TABLE_NAME,
COLUMN_NAME,
DATA_TYPE,
TYPE_NAME,
COLUMN_SIZE,
COLUMN_TEXT
FROM "SYSIBM"."SQLCOLUMNS"
WHERE TABLE_SCHEM = 'SCHEMA'
AND TABLE_NAME = 'TABLE'
This is on DB2 V5R4, and is not a System Table but a SYSTEM VIEW
. In case that you go nuts looking for it on the tables list.
这是在 DB2 V5R4 上,不是系统表,而是SYSTEM VIEW
. 万一你发疯了,在表格列表中寻找它。
回答by tvanharp
-- NOTE: the where clause is case sensitive and needs to be uppercase
-- 注意:where 子句区分大小写,需要大写
select
t.table_schema as Library
,t.table_name
,t.table_type
,c.column_name
,c.ordinal_position
,c.data_type
,c.character_maximum_length as Length
,c.numeric_precision as Precision
,c.numeric_scale as Scale
,c.column_default
,t.is_insertable_into
from sysibm.tables t
join sysibm.columns c
on t.table_schema = c.table_schema
and t.table_name = c.table_name
where t.table_schema = 'MYLIB'
and t.table_name = 'MYTABLE'
order by t.table_name, c.ordinal_position
-- to get a list of all the meta tables:
-- 获取所有元表的列表:
select * from sysibm.tables
where table_schema = 'SYSIBM'
回答by Erik K.
SELECT COLNAME, REMARKS
FROM SYSCAT.COLUMNS
WHERE TABSCHEMA = 'MYSCHEMA'
AND TABNAME = 'MYTABLENAME'
SELECT COLNAME, REMARKS
FROM SYSCAT.COLUMNS
WHERE TABSCHEMA = 'MYSCHEMA'
AND TABNAME = 'MYTABLENAME'
回答by Arijit
select T1.name,T1.creator from sysibm.systables T1,sysibm.syscolumns
T2 where T1.name=T2.tbname and T1.creator=T2.tbccreator and
T1.creator='CREATOR NAME' and T2.name='COLUMN NAME'
回答by Michael Sharek
回答by Michael Sharek
I work on an iSeries DB2 box (v5r4), it is a special flavor of DB2.
我在 iSeries DB2 box (v5r4) 上工作,它是 DB2 的一种特殊风格。
If you're on or connecting to an iSeries (AS/400), the link mentioned by Anton is most excellent (sorry, can't vote yet!)
如果您使用或连接到 iSeries (AS/400),Anton 提到的链接是最棒的(抱歉,还不能投票!)
Describe does not work on an iSeries, but will work with DB2 on the other platforms.
Describe 不适用于 iSeries,但可用于其他平台上的 DB2。
回答by Fima Taf
Worked for me:
对我来说有效:
select * from sysibm.columns
where table_schema = 'MY_SCHEMA'