Does dropping a foreign key constraint drop the corresponding index?

No, you can safely drop a foreign key referential integrity constraint without affecting any underlying indexes.

SQL> create table p(t number primary key);

Table created.

SQL> create table c(f number primary key, t number references p(t));

Table created.

SQL> create index c_t on c(t);

Index created.

SQL> select index_name from user_indexes where table_name = 'C';

INDEX_NAME
------------------------------
SYS_C00413196
C_T

SQL> select constraint_name from user_constraints where r_constraint_name in (select constraint_name from user_constraints where table_name = 'P');

CONSTRAINT_NAME
------------------------------
SYS_C00413197

SQL> insert into c values(1,1);
insert into c values(1,1)
*
ERROR at line 1:
ORA-02291: integrity constraint (FOO.SYS_C00413197) violated - parent key not found


SQL> alter table c drop constraint SYS_C00413197;

Table altered.

SQL> select constraint_name from user_constraints where r_constraint_name in (select constraint_name from user_constraints where table_name = 'P');

no rows selected

SQL> select index_name from user_indexes where table_name = 'C';

INDEX_NAME
------------------------------
SYS_C00413196
C_T

SQL> alter table c add constraint c_t_fk foreign key(t) references p(t);

Table altered.

SQL> select constraint_name from user_constraints where r_constraint_name in (select constraint_name from user_constraints where table_name = 'P');

CONSTRAINT_NAME
------------------------------
C_T_FK

SQL> select index_name from user_indexes where table_name = 'C';

INDEX_NAME
------------------------------
SYS_C00413196
C_T

SQL>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.