Consider the following two tables and their primary keys:
create table testuser.test1 (
col1 number not null,
col2 number not null,
col3 number not null
);
alter table testuser.test1
add constraint test1_pk primary key (col1);
create table testuser.test2 (
col1 number not null,
col2 number not null,
col3 number not null
);
create unique index testuser.test2_pk on testuser.test2 (col1);
alter table testuser.test2
add constraint test2_pk primary key (col1)
using index testuser.test2_pk;
Note that my index has the same name than my primary key: test2_pk.
If I compare the constraints and the indices, I cannot see any difference between the "automatic" index
test1_pk and the "manual" index
test2_pk.
select * from dba_indexes where table_owner = 'TESTUSER' and lower(index_name) like '%test%';
select * from dba_constraints where owner = 'TESTUSER' and lower(constraint_name) like '%test%';
But obviously, Oracle
can tell the difference, because if I now drop the primary keys and check my indices again:
alter table testuser.test1 drop constraint test1_pk;
alter table testuser.test2 drop constraint test2_pk;
select * from dba_indexes where table_owner = 'TESTUSER' and lower(index_name) like '%test%';
the "automatic" index
test1_pk is gone, but the "manual" index
test2_pk is still here (as it should)
My question is:
How can I know if an index is "automatic" (i.e. will be dropped when dropping the primary key) or "manual" (won't be dropped when dropping the primary key) ?
Its not visible in the standard views. (You can see the differences by looking at the data in the tables that underpin those views).
So rather than querying whether it will, you can have explicit control yourself using the "keep index" and "drop index" clauses when you want to drop a constraint.