Foreword

"My journey of mastering oracle is in its nascent stage. I face problem in small-small things. As i'm learning through self studies, through googling, i always come across small-small discoveries, which i think should be shared for beginner's benefits."
-Mithilesh
01/06/2013.

Search This Blog

Thursday, June 6, 2013

Changing 'Primary Key' in Oracle Table

Changing 'Primary Key' is two steps process as under:

Step 1:DROP existing primary key:

alter table my_table drop constraint my_pk;
or,
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;

Step 2: Re-create the primary key:

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.

No comments:

Post a Comment