Hi Tom,
I want to rename a constraint without recreating it because the table contains too many records and time to recreate constraint is unacceptable for my task.
But ALL_OBJECTS and USER_OBJECTS views still display the old constraint name.
I boiled down my problem to the following example:
Create table:
CREATE TABLE ASDF(
ID NUMBER(38, 0) NOT NULL,
CONSTRAINT ASDF_ID PRIMARY KEY (ID)
);
Rename constraint:
alter table ASDF rename constraint ASDF_ID to ASDF_ID2;
But ALL_OBJECT/USER_OBJECTS still displays the old name:
select object_name, object_type from all_objects where object_name like 'ASDF%';
---------------
ASDF TABLE
ASDF_ID INDEX
However these queries return the new name:
select constraint_name from user_constraints where table_name = 'ASDF';
---------------
ASDF_ID2
select constraint_name from user_cons_columns where table_name = 'ASDF';
---------------
ASDF_ID2
How to make ALL_OBJECTS/USER_OBJECTS views to return the new constraint name without recreating the constraint?
You have renamed the constraint!
Constraints don't appear in *OBJECTS. You're seeing the unique index used to police the primary key - not the constraint.
To change this rename the index:
CREATE TABLE ASDF(
ID NUMBER(38, 0) NOT NULL,
CONSTRAINT ASDF_ID PRIMARY KEY (ID)
);
alter index asdf_id rename to asdf_pk;
select object_name, object_type
from user_objects
where object_name like 'ASDF%';
OBJECT_NAME OBJECT_TYPE
ASDF TABLE
ASDF_PK INDEX