Informix iSQL有一个显示所有表的命令“info tables;
”
查看字段及其各自数据类型的语法是“info columns for table;
”
是否有类似的命令显示所有表和所有字段的table.field?
答案 0 :(得分:30)
使用首选的JOIN表示法:
SELECT TRIM(t.tabname) || '.' || TRIM(c.colname) AS table_dot_column
FROM "informix".systables AS t
JOIN "informix".syscolumns AS c ON t.tabid = c.tabid
WHERE t.tabtype = 'T'
AND t.tabid >= 100
ORDER BY t.tabname, c.colno;
或老式的join-in-where-clause符号:
SELECT TRIM(t.tabname) || '.' || TRIM(c.colname) AS table_dot_column
FROM "informix".systables AS t, "informix".syscolumns AS c
WHERE t.tabid = c.tabid
AND t.tabtype = 'T'
AND t.tabid >= 100
ORDER BY t.tabname, c.colno;
假设您使用的是最新版本的IDS,您可以按选择列表中未引用的列进行排序。如果您收到投诉,请将订购列添加到选择列表中。
联合标准是显而易见的; tabtype ='T'仅列出表格,而不列出systables中列出的视图,同义词和其他此类项目; tabid> = 100仅列出在数据库中显式创建的表,而不是系统目录。
这不包括类型信息 - 如果你想要,你必须做更多的工作。您将找到一个文件$INFORMIXDIR/etc/xpg4_is.sql
,其中包含旧版XPG4(X / Open标准)信息模式的粗略近似值(因此文件名)。在那里,有一些函数等可以将syscolumns.coltype
和syscolumns.collength
中的类型信息解码为可识别的字符串。但是,我强烈怀疑它不处理DISTINCT类型,也不处理其他用户定义的类型。我很高兴被证明是错误的,但是......如果你将该文件的相关部分添加到数据库中,那么你也应该能够获得类型信息。
另请注意,ISQL和DB-Access中的所有INFO命令都在前端进行模拟,而不是在IDS服务器中执行。基本上,程序接受请求并将其转换为更复杂的SQL语句。请参阅文件sqlinfo.ec
中的代码,该文件是SQLCMD的一部分(可从IIUG Software Archive获得),以了解我的SQLCMD程序如何处理INFO语句。 (注意:SQLCMD的INFO输出格式与ISQL和DB-Access的INFO输出不同。)
答案 1 :(得分:1)
使用syscolumns表。 IBM Informix Guide to SQL
中描述了此类信息我已经完成了简单的Python实用程序,它显示了Informix,Oracle和PostgreSQL的架构信息。如果必须比较数据库,它们很有用。
答案 2 :(得分:1)
正如Jonathan Leffer的回答所提到的那样,对列类型和列详细信息的完整处理变得复杂,如SYSCOLUMNS文档中所示。但是,如果您正在查看不使用更复杂类型的数据库,那么对其脚本的添加将显示基本类型以及是否允许NULL:
SELECT TRIM(t.tabname) || '.' || TRIM(c.colname) AS table_dot_column,
CASE
WHEN MOD(coltype,256)=0 THEN 'CHAR'
WHEN MOD(coltype,256)=1 THEN 'SMALLINT'
WHEN MOD(coltype,256)=2 THEN 'INTEGER'
WHEN MOD(coltype,256)=3 THEN 'FLOAT'
WHEN MOD(coltype,256)=4 THEN 'SMALLFLOAT'
WHEN MOD(coltype,256)=5 THEN 'DECIMAL'
WHEN MOD(coltype,256)=6 THEN 'SERIAL'
WHEN MOD(coltype,256)=7 THEN 'DATE'
WHEN MOD(coltype,256)=8 THEN 'MONEY'
WHEN MOD(coltype,256)=9 THEN 'NULL'
WHEN MOD(coltype,256)=10 THEN 'DATETIME'
WHEN MOD(coltype,256)=11 THEN 'BYTE'
WHEN MOD(coltype,256)=12 THEN 'TEXT'
WHEN MOD(coltype,256)=13 THEN 'VARCHAR'
WHEN MOD(coltype,256)=14 THEN 'INTERVAL'
WHEN MOD(coltype,256)=15 THEN 'NCHAR'
WHEN MOD(coltype,256)=16 THEN 'NVARCHAR'
WHEN MOD(coltype,256)=17 THEN 'INT8'
WHEN MOD(coltype,256)=18 THEN 'SERIAL8'
WHEN MOD(coltype,256)=19 THEN 'SET'
WHEN MOD(coltype,256)=20 THEN 'MULTISET'
WHEN MOD(coltype,256)=21 THEN 'LIST'
WHEN MOD(coltype,256)=22 THEN 'ROW (unnamed)'
WHEN MOD(coltype,256)=23 THEN 'COLLECTION'
WHEN MOD(coltype,256)=40 THEN 'LVARCHAR fixed-length opaque types'
WHEN MOD(coltype,256)=41 THEN 'BLOB, BOOLEAN, CLOB variable-length opaque types'
WHEN MOD(coltype,256)=43 THEN 'LVARCHAR (client-side only)'
WHEN MOD(coltype,256)=45 THEN 'BOOLEAN'
WHEN MOD(coltype,256)=52 THEN 'BIGINT'
WHEN MOD(coltype,256)=53 THEN 'BIGSERIAL'
WHEN MOD(coltype,256)=2061 THEN 'IDSSECURITYLABEL'
WHEN MOD(coltype,256)=4118 THEN 'ROW (named)'
ELSE TO_CHAR(coltype)
END AS Type,
BITAND(coltype,256)=256 AS NotNull
FROM "informix".systables AS t
JOIN "informix".syscolumns AS c ON t.tabid = c.tabid
WHERE t.tabtype = 'T'
AND t.tabid >= 100
ORDER BY t.tabname, c.colno;
答案 3 :(得分:0)
我做了一个基本的检查主键列。 还添加了列顺序,数据类型长度。 这提供了生成ETL的基本信息
SELECT TRIM(t.tabname) AS TableName
,c.colno AS ColumnOrder
,TRIM(c.colname) AS ColumnName
,CASE
WHEN MOD(coltype,256)=0 THEN 'CHAR'
WHEN MOD(coltype,256)=1 THEN 'SMALLINT'
WHEN MOD(coltype,256)=2 THEN 'INTEGER'
WHEN MOD(coltype,256)=3 THEN 'FLOAT'
WHEN MOD(coltype,256)=4 THEN 'SMALLFLOAT'
WHEN MOD(coltype,256)=5 THEN 'DECIMAL'
WHEN MOD(coltype,256)=6 THEN 'SERIAL'
WHEN MOD(coltype,256)=7 THEN 'DATE'
WHEN MOD(coltype,256)=8 THEN 'MONEY'
WHEN MOD(coltype,256)=9 THEN 'NULL'
WHEN MOD(coltype,256)=10 THEN 'DATETIME'
WHEN MOD(coltype,256)=11 THEN 'BYTE'
WHEN MOD(coltype,256)=12 THEN 'TEXT'
WHEN MOD(coltype,256)=13 THEN 'VARCHAR'
WHEN MOD(coltype,256)=14 THEN 'INTERVAL'
WHEN MOD(coltype,256)=15 THEN 'NCHAR'
WHEN MOD(coltype,256)=16 THEN 'NVARCHAR'
WHEN MOD(coltype,256)=17 THEN 'INT8'
WHEN MOD(coltype,256)=18 THEN 'SERIAL8'
WHEN MOD(coltype,256)=19 THEN 'SET'
WHEN MOD(coltype,256)=20 THEN 'MULTISET'
WHEN MOD(coltype,256)=21 THEN 'LIST'
WHEN MOD(coltype,256)=22 THEN 'ROW (unnamed)'
WHEN MOD(coltype,256)=23 THEN 'COLLECTION'
WHEN MOD(coltype,256)=40 THEN 'LVARCHAR fixed-length opaque types'
WHEN MOD(coltype,256)=41 THEN 'BLOB, BOOLEAN, CLOB variable-length opaque types'
WHEN MOD(coltype,256)=43 THEN 'LVARCHAR (client-side only)'
WHEN MOD(coltype,256)=45 THEN 'BOOLEAN'
WHEN MOD(coltype,256)=52 THEN 'BIGINT'
WHEN MOD(coltype,256)=53 THEN 'BIGSERIAL'
WHEN MOD(coltype,256)=2061 THEN 'IDSSECURITYLABEL'
WHEN MOD(coltype,256)=4118 THEN 'ROW (named)'
ELSE TO_CHAR(coltype)
END AS Datatype
,c.collength AS DatatypeLength
,CASE WHEN NVL(
(
SELECT MAX(i.idxname)
FROM "informix".sysconstraints cn inner join "informix".sysindexes i
on cn.idxname = i.idxname
and cn.tabid = i.tabid
where cn.constrtype = 'P'
AND cn.tabid = t.tabid
AND
(c.colno = i.part1
OR c.colno = i.part2
OR c.colno = i.part3
OR c.colno = i.part4
OR c.colno = i.part5
OR c.colno = i.part6
OR c.colno = i.part7
OR c.colno = i.part8
OR c.colno = i.part9
OR c.colno = i.part10
OR c.colno = i.part11
OR c.colno = i.part12
OR c.colno = i.part13
OR c.colno = i.part14
OR c.colno = i.part15
OR c.colno = i.part16
)
),'') = '' THEN 0 ELSE 1 END AS PK
FROM "informix".systables AS t JOIN "informix".syscolumns AS c
ON t.tabid = c.tabid
WHERE t.tabtype = 'T'
AND t.tabid >= 100
--AND t.tabname = 'resource'
ORDER BY t.tabname, c.colno;