Drop Primary Key Oracle

Before stepping into this article, gain knowledge about the primary key. Click here to know about the Primary key. Also, click the link to learn the concept for adding a Primary key to an existing table.

The concept of primary key and foreign key is really important, to interlink the data present in different tables in a database. With continuous increased data, we need to organize that data, just to make it easily accessible. We can also drop an already existing primary key in a table without actually affecting any values present in it. Follow the syntax below to perform a similar task.

Drop Primary Key in Oracle Syntax

Alter Table Table_Name
drop CONSTRAINT Constraint_name;

Oracle Drop Primary Key Example 1

We have a Stu table :

Oracle Drop Primary Key Example

wherein we have the Roll_No column as a primary key of that table. The that we used to create a Primary key is:

ALTER TABLE Stu
ADD CONSTRAINT stu_pk PRIMARY KEY (Roll_No);

Now to drop the primary key concept from a particular Roll_no column, we can write a code as:

Alter Table Stu
drop CONSTRAINT stu_pk;

Output

Oracle Drop Primary Key Example

Oracle Drop Primary Key Example 2

Let's consider a table Stu wherein Two columns are made as a Primary key. Roll_No and Stu_id are the names of those two columns. Code used to create them as a primary key is:

ALTER TABLE Stu
ADD CONSTRAINT stu_pk PRIMARY KEY (Roll_No, Stu_id);

Now, to drop both of the Primary keys of the table we can write the following code:

Alter Table Stu
drop CONSTRAINT stu_pk;

Output

Oracle Drop Primary Key Example