MySQL

How to Remove a Primary Key in MySQL

In this tutorial, we are going to see how to remove a primary key in MySQL. In MySQL, we can remove the “PRIMARY KEY” constraint from a column of an existing table by using DROP keyword with ALTER TABLE statement.
 

 

How to Remove a Primary Key in MySQL

Suppose we have the table ‘Persons’ with the constraint PRIMARY KEY on the column “PersonID”:

> SELECT * FROM Persons;

+----------+-----------+--------+-------------------------------+
| PersonID |    Name   |  age   |             Address           |
+----------+-----------+--------+-------------------------------+
|    101   |    Alex   |   25   | 819 Saint Francis Way         |
|    102   |   Emily   |   15   | 171 Jarvisville Road Michigan |
|    103   |   Jean    |   35   | 188 Clay Street Indiana       |
|    104   |    Bob    |   40   | 285 Java Lane Missouri        |
+----------+-----------+--------+-------------------------------+

Now, if we want to remove the “PRIMARY KEY” constraint, we can use the statement ALTER TABLE as follows:

ALTER table Persons DROP PRIMARY KEY;
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *