0

我正在尝试SYSCAT使用下面的查询从表中查询某些用户表的唯一索引,该查询使用 4 个目录表(INDEXES、、、、INDEXCOLUSE)。我意识到所有索引都在and表中,但其中许多索引在 and 表中丢失。TABCONSTCONSTDEPINDEXESINDEXCOLUSETABCONSTCONSTDEP

是否有任何理由在TABCONSTCONSTDEP表中丢失数据?是否有一些程序可以刷新这些目录表中的数据?

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 索引而不仅仅是索引!

4

1 回答 1

1

当您直接创建索引时,它不是约束:

CREATE UNIQUE INDEX myindex on mytab(mycol)

但是,如果您创建或更改表并使用UNIQUE来声明单个列或多个列,则它是一个约束。

于 2018-08-02T07:19:43.003 回答