日期:2014-05-16 浏览次数:20651 次
原文地址:http://blog.csdn.net/huanzhulouzhu/article/details/6274971
?
?
用user_indexes和user_ind_columns系统表查看已经存在的索引
对于系统中已经存在的索引我们可以通过以下的两个系统视图(user_indexes和user_ind_columns)来查看其具体内
容,例如是属于那个表,哪个列和,具体有些什么参数等等。
user_indexes:???? 系统视图存放是索引的名称以及该索引是否是唯一索引等信息。
user_ind_column:? 系统视图存放的是索引名称,对应的表和列等。
?
查看索引个数和类别:
SQL> select * from user_indexes where table='表名' ;
查看索引被索引的字段:
SQL> select * from user_ind_columns where 
index_name=upper('&index_name');
?
我们可以通过类似下面的语句来查看一个表的索引的基本情况:
select user_ind_columns.index_name,user_ind_columns.column_name,
user_ind_columns.column_position,user_indexes.uniqueness
from user_ind_columns,user_indexes
where user_ind_columns.index_name = user_indexes.index_name
and user_ind_columns.table_name = ‘你想要查询的表名字’;
通过这条SQL语句我们能查看到一个表的具体的索引的情况,如果你想对这表的索引进行进一步的探究你应该到user_indexes中去具
体的看以下这个索引的基本情况。
?
?
完整性约束
  DBA_CONSTRAINTS、ALL_CONSTRAINTS和USER_CONSTRAINST? 
显示有关约束的一般信息。
  DBA_CONS_COLUMNS、ALL_CONS_COLUMNS和USER_CONS_COLUMNS 
显示有关列的相关约束的一般信息。
?
ALL_CONS_COLUMNS 视图和DBA_CONS_COLUMNS 视图与USER_CONS_COLUMNS有相同的列定义。
ALL_CONS_COLUMNS 视图能够显示用户可以访问的所有表上约束的列信息,而不管所有者是谁。
DBA_CONS_COLUMNS
 视图列出了整个数据库的列级约束信息。
USER_CONS_COLUMNS
?
user_constraints 和 user_cons_columns表得作用及其联系
user_constraints:? 
是表约束的视图,描述的是约束类型(constraint_type)是什么,属于哪些表(table_name),如果约束的类型为R(外键)的话,那
么r_constraint_name字段存放的就是被引用主表中的主键约束名。?? 
user_cons_columns: 是表约束字段的视图,说明表中的和约束相关的列参与了哪些约束。这些约束有主键约束,外键约束,索引约束.
两者可以通过(owner,constraint_name,table_name)关联:
select 
a.owner 外键拥有者, 
a.table_name 外键表, 
substr(c.column_name,1,127)
 外键列, 
b.owner 主键拥有者, 
b.table_name 主键表, 
substr(d.column_name,1,127)
 主键列 
from 
user_constraints a, 
user_constraints b, 
user_cons_columns
 c, 
user_cons_columns d 
where 
??? 
a.r_constraint_name=b.constraint_name 
and a.constraint_type='R' 
and
 b.constraint_type='P' 
and a.r_owner=b.owner 
and 
a.constraint_name=c.constraint_name 
and 
b.constraint_name=d.constraint_name 
and a.owner=c.owner 
and 
a.table_name=c.table_name 
and b.owner=d.owner 
and 
b.table_name=d.table_name 
数据字典表列说明:
desc user_constraints
Name??????????????????????????????????????????????????????????????????????????????????
 
Comments???????????????????????????????????????????????????????????????????
 
-----------------??????????????? 
---------------------------------------
 
OWNER??????????????????????????????????????????????????????????????????
 Owner of the 
table????????????????????????????????????????????????????????? 
CONSTRAINT_NAME????????????????????????????????????????????
 Name associated with constraint 
definition????????????????????????????????? 
CONSTRAINT_TYPE?????????????????????????????????????????????
 Type of constraint 
definition?????????????????????????????????????????????? 
TABLE_NAME?????????????????????????????????????????????????????????
 Name associated with table with constraint 
definition?????????????????????? 
SEARCH_CONDITION????????????????????????????????????????????
 Text of search condition for table 
check??????????????????????????????????? 
R_OWNER????????????????????????????????????????????????????????????????
 Owner of table used in referential 
constraint?????????????????????????????? 
R_CONSTRAINT_NAME?????????????????????????????????????????
 Name of unique constraint definition for referenced 
table?????????????????? 
DELETE_RULE?????????????????????????????????????????????????????????
 The delete rule for a referential 
constraint??????????????????????????????? 
STATUS?????????????????????????????????????????????????????????????????????
 Enforcement status of constraint -? E