

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove Primary Key in MySQL?
To remove primary key in MySQL, use tje drop primary key command. To understand the concept, let us create a table with column as primary key.
mysql> create table PrimaryKeyDemo -> ( -> id int not null, -> Primary key(id) -> ); Query OK, 0 rows affected (0.60 sec)
Let us check the description of the table with the help of DESC command. The query is as follows.
mysql> desc PrimaryKeyDemo;
The following is the output.
+-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | +-------+---------+------+-----+---------+-------+ 1 row in set (0.06 sec)
Look at the output above, there is a column ‘Key’ which has the PRI keyword. This itself says that the “id” column is primary key. Now, let us remove the primary key with the help of ALTER and DROP command. The query is as follows.
mysql> alter table PrimaryKeyDemo drop primary key; Query OK, 0 rows affected (1.70 sec) Records: 0 Duplicates: 0 Warnings: 0
Let us now check whether primary key is removed or not successfully.
mysql> DESC PrimaryKeyDemo;
The following is the output that won’t display primary key now, since we have deleted it above.
+-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | id | int(11) | NO | | NULL | | +-------+---------+------+-----+---------+-------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- MySQL ALTER column to remove primary key and auto_increment?
- Can we remove a primary key from MySQL table?
- Reset Primary Key in MySQL
- How to remove primary key from MongoDB?
- Primary key Vs Unique key
- Set existing column as Primary Key in MySQL?
- Is the primary key automatically indexed in MySQL?
- How do I drop a primary key in MySQL?
- How can we remove PRIMARY KEY constraint from a column of an existing MySQL table?
- Difference between Primary Key and Candidate key
- Difference between Primary Key and Unique key
- How can I define a column of a MySQL table PRIMARY KEY without using the PRIMARY KEY keyword?
- How to make MySQL table primary key auto increment?
- Two columns as primary key with auto-increment in MySQL?
- How to get primary key of a table in MySQL?
Advertisements