我正在尝试SYSCAT
使用下面的查询从表中查询某些用户表的唯一索引,该查询使用 4 个目录表(INDEXES
、、、、INDEXCOLUSE
)。我意识到所有索引都在and表中,但其中许多索引在 and 表中丢失。TABCONST
CONSTDEP
INDEXES
INDEXCOLUSE
TABCONST
CONSTDEP
是否有任何理由在TABCONST
和CONSTDEP
表中丢失数据?是否有一些程序可以刷新这些目录表中的数据?
SELECT
T.TABSCHEMA AS TABLE_SCHEMA,
T.TABNAME AS TABLE_NAME,
CASE T.TYPE
WHEN 'F' THEN 'Foreign Key'
WHEN 'I' THEN 'Functional Dependency'
WHEN 'K' THEN 'Check'
WHEN 'P' THEN 'Primary Key'
WHEN 'U' THEN 'Unique'
END AS TYPE,
I.INDSCHEMA AS INDEX_SCHEMA,
I.INDNAME AS INDEX_NAME,
U.COLNAME AS COLUMN_NAME,
U.COLSEQ AS COLUMN_ORDINAL,
CASE U.COLORDER
WHEN 'A' THEN 'Ascending'
WHEN 'D' THEN 'Descending'
WHEN 'I' THEN 'Included (unordered)'
END AS COLUMN_SORRING
FROM
SYSCAT.TABCONST T
INNER JOIN
SYSCAT.CONSTDEP C
ON T.CONSTNAME = C.CONSTNAME
INNER JOIN
SYSCAT.INDEXES I
ON
C.BSCHEMA = I.INDSCHEMA AND
C.BNAME = I.INDNAME
INNER JOIN
SYSCAT.INDEXCOLUSE U
ON
I.INDSCHEMA = U.INDSCHEMA AND
I.INDNAME = U.INDNAME
WHERE
TRIM(UPPER(T.TABSCHEMA)) = 'MYSCHEMA' AND
TRIM(UPPER(T.TABNAME)) = 'MYTABLE'AND
C.BTYPE = 'I'
--INDICES ONLY
ORDER BY
T.TABSCHEMA,
T.TABNAME,
I.INDSCHEMA,
I.INDNAME
;
笔记
编辑问题的标题:忘了说这完全是关于 UNIQUE 索引而不仅仅是索引!