Click here to Skip to main content
15,891,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Oracle DB and 1 table e.g. Employee, EMployee table has 4 columns employeeAge, EmployeeNo, EmployeeSal, isActive, Now it has composite key based on Employeeno and EmpoyeeSal then i want to delete Composite key and add new PK like EmpId.

How do i do this in oracle??

What I have tried:

I tried this syntax 
Alter table Employee drop primary key drop Index

but this also deletes data, I want to persist my data. 
Posted
Updated 29-Jul-21 3:11am

1 solution

You should just be able to use
SQL
Alter table Employee drop primary key;
and then
SQL
ALTER TABLE Employee ADD CONSTRAINT pk_empid PRIMARY KEY (EmpId);
I would not have expected drop Index to delete any data - perhaps you fell foul of this note from the documentation
Quote:
When you drop an index, Oracle Database invalidates all objects that depend on the underlying table, including views, packages, package bodies, functions, and procedures.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900