Oracle 查询主键和索引

时间:2022-10-06 21:16:00

ORACLE: 

1、查主键名称: 
select * from user_constraints 
where table_name = 'AAA' 
and constraint_type ='P'; 


查主键对应的列: 
select * from user_cons_columns 
where table_name = 'AAA' 
and constraint_name = 'PK_AAA'; (PK_AAA 是主键名)

2、查索引名称: 
select * from user_indexes 
where table_name = 'AAA'; 
查索引对应的列: 
select * from user_ind_columns 
where table_name = 'AAA' 
and index_name = 'INDX_BA'; (INDX_BA 是 索引名)

了解几个字典表的用处 如:user_constraints 

添加主键:

alter table TableName

add constraint PK NAME
primary key("ACCOUNTINGTASKID"...);

删除主键:

alter table EXTRACTED_POSTING(tablle name)

drop constraint EXTRACTED_POSTING_ACCTID_PK;(PK name)