Change Primary Key

后端 未结 3 2002
面向向阳花
面向向阳花 2020-12-14 06:31

I have a table in Oracle which has following schema:

City_ID  Name  State  Country  BuildTime  Time

When I declared the table my primary key

3条回答
  •  醉话见心
    2020-12-14 06:40

    Sometimes when we do these steps:

     alter table my_table drop constraint my_pk; 
     alter table my_table add constraint my_pk primary key (city_id, buildtime, time);
    

    The last statement fails with

    ORA-00955 "name is already used by an existing object"

    Oracle usually creates an unique index with the same name my_pk. In such a case you can drop the unique index or rename it based on whether the constraint is still relevant.

    You can combine the dropping of primary key constraint and unique index into a single sql statement:

    alter table my_table drop constraint my_pk drop index; 
    

    check this: ORA-00955 "name is already used by an existing object"

提交回复
热议问题