Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: relationship between unique index and constraint
One more detail:
"But since Oracle used that index to enforce the unique constraint, it was dropped to un-enforce the constraint."
However if the enforcing index for the PK or unique constraint is not a unique index, it will not be dropped along with the PK or unique constraint.
-----Original Message-----
Here is the lowdown on the issue:
When you create a unique CONSTRAINT, Oracle creates a unique INDEX to
enforce it.
When you create a unique INDEX, a constraint is NOT automatically created,
but the rdbms engine reports the same message as if the constraint name was
violated.
So what happens when you create a unique INDEX first and then add a unique CONSTRAINT of the same name later?
SQL> create unique index in_trans_01 on trans (col1);
Index created.
SQL> select index_name from user_indexes where table_name = 'TRANS';
INDEX_NAME
Table altered.
SQL> select index_name from user_indexes where table_name = 'TRANS';
INDEX_NAME
SQL> select constraint_name from user_constraints where table_name = 'TRANS'; CONSTRAINT_NAME
SQL> alter table trans drop constraint uk_trans_01;
Table altered.
SQL> select index_name from user_indexes where table_name = 'TRANS';
no rows selected
Well, what happened to the index IN_TRANS_01? We didn't drop that. But since Oracle used that index to enforce the unique constraint, it was dropped to un-enforce the constraint. This is expected feature; although it come as a surprise.
In Oracle 9i, though, you have a new clause KEEP INDEX that will keep the index while dropping the constraint.
-- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Jacques Kilchoer INET: Jacques.Kilchoer_at_quest.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting servicesReceived on Fri Apr 18 2003 - 16:06:55 CDT
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).