oracle如何查询索引 oracle索引查看

如何在oracle中查询所有用户表的表名、主键名称、索引、外键等

1、查找表的所有索引(包括索引名,类型,构成列):

创新互联-专业网站定制、快速模板网站建设、高性价比灵宝网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式灵宝网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖灵宝地区。费用合理售后完善,十多年实体公司更值得信赖。

select

t.*,i.index_type

from

user_ind_columns

t,user_indexes

i

where

t.index_name

=

i.index_name

and

t.table_name

=

i.table_name

and

t.table_name

=

要查询的表

2、查找表的主键(包括名称,构成列):

select

cu.*

from

user_cons_columns

cu,

user_constraints

au

where

cu.constraint_name

=

au.constraint_name

and

au.constraint_type

=

'P'

and

au.table_name

=

要查询的表

3、查找表的唯一性约束(包括名称,构成列):

select

column_name

from

user_cons_columns

cu,

user_constraints

au

where

cu.constraint_name

=

au.constraint_name

and

au.constraint_type

=

'U'

and

au.table_name

=

要查询的表

4、查找表的外键(包括名称,引用表的表名和对应的键名,下面是分成多步查询):

select

*

from

user_constraints

c

where

c.constraint_type

=

'R'

and

c.table_name

=

要查询的表

查询外键约束的列名:

select

*

from

user_cons_columns

cl

where

cl.constraint_name

=

外键名称

查询引用表的键的列名:

select

*

from

user_cons_columns

cl

where

cl.constraint_name

=

外键引用表的键名

5、查询表的所有列及其属性

oracle如何查看表索引是否有效?

通过PL/SQL可以直接查看某表是否建索引,通过SQL查询selectstatus,T.*fromuser_indexesT wheretable_name='表名'

oracle查看有效索引是这个:selectstatus,T.*fromuser_indexesT,wheretable_name='TABLE1'

最好弄个图像界面软件,就能知道,比如:PL/SQLDeveloper

数据库中的失效的索引、索引分区、子分区:如果不是失效的索引,那么都是有效的。

oracle 如何查看某个表是否已有索引

oracle查看有效索引是这个:

select status,T.* from user_indexes T

where table_name='TABLE1'

最好弄个图像界面软件,就能知道,比如:PL/SQL Developer

怎么查看索引oracle,建索引

一、查看和建立索引

select

*

from

user_indexes

where

table_name

=

'student'

create

index

i_student_num

on

student(num)

二、使用索引的注意点

①类型匹配

若student中num列是varchar类型,语句select

*

from

student

where

num

=

100

该语句被转化为select

*

from

student

where

to_number(num)

=

100,该列的索引就失效了。

②避免索引列参与计算

索引失效:select

*

from

student

where

num

*

10

10000

索引有效:select

*

from

student

where

num

10000

/

10

③不要对索引列使用IS

NULL或IS

NOT

NULL

原则上对某一个列建立索引的时候,该列就不应该允许为空。

索引失效:select

*

from

student

where

num

is

null

Oracle下查看索引的语句

1. 查询一张表里面索引 

select*from user_indexes where table_name=upper('bills');

2. 查询被索引字段 

select* from user_ind_columns where index_name=('in_bills') and table_name='表名';

select* from user_ind_columns where table_name='MPI_DEMOGRAPHICINFO';

3. 给某一字段创建索引 

create index in_bills on bills(account_id);

删除约束语句格式:

alter table 表名 drop CONSTRAINT 主键约束 名;

如:

alter table 修课表 drop CONSTRAINT pk_xh_kc;

oracle怎么通过索引查询数据语句

oracle对于数据库中的表信息,存储在系统表中。查询已创建好的表索引,可通过相应的sql语句到相应的表中进行快捷的查询:\x0d\x0a1. 根据表名,查询一张表的索引\x0d\x0a\x0d\x0aselect * from user_indexes where table_name=upper('表名');\x0d\x0a\x0d\x0a2. 根据索引号,查询表索引字段\x0d\x0a\x0d\x0aselect * from user_ind_columns where index_name=('索引名');\x0d\x0a\x0d\x0a3.根据索引名,查询创建索引的语句\x0d\x0a\x0d\x0aselect dbms_metadata.get_ddl('INDEX','索引名', ['用户名']) from dual ; --['用户名']可省,默认为登录用户\x0d\x0a\x0d\x0aPS:dbms_metadata.get_ddl还可以得到建表语句,如:\x0d\x0a\x0d\x0aSELECT DBMS_METADATA.GET_DDL('TABLE','表名', ['用户名']) FROM DUAL ; //取单个表的建表语句,['用户名']可不输入,默认为登录用户\x0d\x0aSELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) FROM USER_TABLES u; //取用户下所有表的建表语句\x0d\x0a\x0d\x0a当然,也可以用pl/sql developer工具来查看相关的表的各种信息。


文章名称:oracle如何查询索引 oracle索引查看
标题网址:http://pwwzsj.com/article/hgsoph.html