Skip to Main Content
  • Questions
  • After renaming constraint, ALL_OBJECTS still displays the old name.

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Viktor.

Asked: October 09, 2024 - 12:58 pm UTC

Last updated: October 10, 2024 - 12:52 pm UTC

Version: 19.0.0.0.0

Viewed 10K+ times! This question is

You Asked

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?

and Chris said...

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    

Rating

  (1 rating)

Comments

Issue resolved

Viktor, October 09, 2024 - 3:43 pm UTC

Chris, thank you very much! It resolved my issue.
Chris Saxon
October 10, 2024 - 12:52 pm UTC

You're welcome