2017-05-08 135 views
-4

我不是DBA,因此提出这个问题。有人可以告诉我什么是下面提到的查询的意义:oracle对所有者的唯一索引

select i.index_name, 
     NVL(c.column_name,' '), 
     NVL(c.DESCEND, 'ASC') 
    from all_indexes i, all_ind_columns c 
    where i.index_name = c.index_name 
    and (i.INDEX_TYPE = 'NORMAL' or i.INDEX_TYPE = 'FUNCTION-BASED NORMAL') 
    and i.table_name = name 
    and i.owner = c.index_owner 
    and i.table_owner = owner 
    and c.table_name = name 
    and c.table_owner = owner 
    and i.uniqueness = 'UNIQUE' 
    order by c.index_name, c.column_position 

这是一种关于索引的约束检查。请分享你的想法。

回答

1

你是什么意思的“关于索引的约束检查”?我不熟悉这个概念。在任何情况下:此查询都将数据库的所有者(模式,用户)和该模式中的表的名称(该所有者拥有)作为输入。它找到该表上的所有唯一索引(实施唯一值的索引),包括例如主键的索引,索引所在的列或列集以及索引是按升序还是降序排序。这是一个相对标准的查询,用于查找有关架构中的表上唯一索引的信息。

例如,大多数Oracle安装都带有标准样本架构(所有者)HR,其中有几个表,其中包括一个名为EMPLOYEES的表。此表具有主键,员工ID以及员工电子邮件上的附加唯一键。以下是查询,分别将ownername分别硬编码为'HR''EMPLOYEES',并输出。请注意,编写查询的人没有将别名提供给SELECT中的最后两列,因此输出看起来有点丑陋。

select i.index_name, 
     NVL(c.column_name,' '), 
     NVL(c.DESCEND, 'ASC') 
    from all_indexes i, all_ind_columns c 
    where i.index_name = c.index_name 
    and (i.INDEX_TYPE = 'NORMAL' or i.INDEX_TYPE = 'FUNCTION-BASED NORMAL') 
    and i.table_name = 'EMPLOYEES' 
    and i.owner = c.index_owner 
    and i.table_owner = 'HR' 
    and c.table_name = 'EMPLOYEES' 
    and c.table_owner = 'HR' 
    and i.uniqueness = 'UNIQUE' 
    order by c.index_name, c.column_position 
; 

INDEX_NAME  NVL(C.COLUMN_NAME,'') NVL(C.DESCEND,'ASC') 
------------- --------------------- -------------------- 
EMP_EMAIL_UK EMAIL     ASC 
EMP_EMP_ID_PK EMPLOYEE_ID   ASC