达梦数据库、oracle数据库如何判断指定表有没有建立索引?对应的表有没有索引查询方法

时间:2022-07-25
本文章向大家介绍达梦数据库、oracle数据库如何判断指定表有没有建立索引?对应的表有没有索引查询方法,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

sm_appmenuitem 这个演示表有 5 个索引。 我在不知道的情况下想知道这个表的索引有没有建成功,或者说我现在想知道这个表的索引有哪些,就要来查询了。 索引表查询方法如下,把对应的表放到括号里就能查出来了,达梦数据库和 oracle 数据库通用这个方法。

# 这两个方法都可以,属于全局级的表。
select * from user_indexes where table_name=upper('sm_appmenuitem'); 
select * from user_ind_columns where table_name = upper('sm_appmenuitem');

5 个索引相当于 5 的阶乘。现在查询时间 2 秒的话,如果没有索引,查询时间就是 25 次方秒 ≈ 32 秒,可见索引的重要性。

索引建表过程:

/* indexcode: i_sm_appmenuitem_1 */
create  index i_sm_appmenuitem_1 on sm_appmenuitem (pk_menuitem)
/

/* indexcode: i_sm_appmenuitem_2 */
create  index i_sm_appmenuitem_2 on sm_appmenuitem (menuitemcode)
/

/* indexcode: i_sm_appmenuitem_3 */
create  index i_sm_appmenuitem_3 on sm_appmenuitem (appid)
/

/* indexcode: i_sm_appmenuitem_4 */
create  index i_sm_appmenuitem_4 on sm_appmenuitem (appcode)
/

/* indexcode: i_sm_appmenuitem_5 */
create  index i_sm_appmenuitem_5 on sm_appmenuitem (menuitemname)
/