显示Oracle某一张表的所有索引
Posted dingdingfish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了显示Oracle某一张表的所有索引相关的知识,希望对你有一定的参考价值。
此SQL来自Oracle SQL*Plus: The Definitive Guide, 2nd Edition,只做了微小的修改:
COLUMN index_name FORMAT A20
COLUMN index_type FORMAT A10
COLUMN UNIQUENESS FORMAT A10
COLUMN column_name FORMAT A15
SELECT ai.index_name, ai.index_type, ai.uniqueness, aic.column_name
FROM dba_indexes ai INNER JOIN dba_ind_columns aic
ON ai.owner = aic.index_owner
AND ai.index_name = aic.index_name
WHERE ai.owner = '&owner'
AND ai.table_name = UPPER('&table_name')
ORDER BY ai.index_name, aic.column_position;
以下为运行示例:
old:SELECT ai.index_name, ai.index_type, ai.uniqueness, aic.column_name
FROM dba_indexes ai INNER JOIN dba_ind_columns aic
ON ai.owner = aic.index_owner
AND ai.index_name = aic.index_name
WHERE ai.owner = '&owner'
AND ai.table_name = UPPER('&table_name')
ORDER BY ai.index_name, aic.column_position
new:SELECT ai.index_name, ai.index_type, ai.uniqueness, aic.column_name
FROM dba_indexes ai INNER JOIN dba_ind_columns aic
ON ai.owner = aic.index_owner
AND ai.index_name = aic.index_name
WHERE ai.owner = 'HR'
AND ai.table_name = UPPER('employees')
ORDER BY ai.index_name, aic.column_position
INDEX_NAME INDEX_TYPE UNIQUENESS COLUMN_NAME
-------------------- ---------- ---------- ---------------
EMP_DEPARTMENT_IX NORMAL NONUNIQUE DEPARTMENT_ID
EMP_EMAIL_UK NORMAL UNIQUE EMAIL
EMP_EMP_ID_PK NORMAL UNIQUE EMPLOYEE_ID
EMP_JOB_IX NORMAL NONUNIQUE JOB_ID
EMP_MANAGER_IX NORMAL NONUNIQUE MANAGER_ID
EMP_NAME_IX NORMAL NONUNIQUE LAST_NAME
EMP_NAME_IX NORMAL NONUNIQUE FIRST_NAME
7 rows selected.
以上是关于显示Oracle某一张表的所有索引的主要内容,如果未能解决你的问题,请参考以下文章
在oracle中如何查询一张表的所有数据结构,包括字段,视图,索引,约束
Oracle如何查询一个用户所创建的表 以及 如何查询一张表的主人