Change Primary Key

后端 未结 3 1998
面向向阳花
面向向阳花 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:57

    You will need to drop and re-create the primary key like this:

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

    However, if there are other tables with foreign keys that reference this primary key, then you will need to drop those first, do the above, and then re-create the foreign keys with the new column list.

    An alternative syntax to drop the existing primary key (e.g. if you don't know the constraint name):

    alter table my_table drop primary key;
    

提交回复
热议问题