Change Primary Key

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

    Assuming that your table name is city and your existing Primary Key is pk_city, you should be able to do the following:

    ALTER TABLE city
    DROP CONSTRAINT pk_city;
    
    ALTER TABLE city
    ADD CONSTRAINT pk_city PRIMARY KEY (city_id, buildtime, time);
    

    Make sure that there are no records where time is NULL, otherwise you won't be able to re-create the constraint.

提交回复
热议问题