oracle - Not able to add a new column to the existing primary key -


i have primary key pk1 table table1. need add 1 more column existing primary key. tying following alter script

alter table table1 add constraint "primarykeys" primary key ("pk1", "pk2");  error report: sql error: ora-02260: table can have 1 primary key 02260. 00000 -  "table can have 1 primary key" *cause:    self-evident. *action:   remove primary key. 

how can add 1 more column primary key, without affecting data(data has been verified , there no duplication.)

if have concern new data violates pk can added during time interval when old pk dropped, new 1 not created, can create unique index first :

create unique index idxu_table1_pk on table1(pk1,pk2); alter table table1 drop constraint [old_pk_constraint_name] ; alter table table1 add constraint "primarykeys" primary key    (pk1,pk2) using index idxu_table1_pk; 

another option keep index associated old pk constraint until new pk created :

alter table table1 drop constraint [old_pk_constraint_name] keep index; alter table table1 add constraint "primarykeys" primary key    (pk1,pk2) ; drop index [name of unique index associated old pk constraint]; 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -