
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we remove PRIMARY KEY constraint from a column of an existing MySQL table?
We can remove PRIMARY KEY constraint from a column of an existing table by using DROP keyword along with ALTER TABLE statement.
Example
Suppose we have a table ‘Player’ having a PRIMARY KEY constraint on column ‘ID’ as follows −
mysql> DESCRIBE Player; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | ID | int(11) | NO | PRI | NULL | | | Name | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.04 sec)
Now if we want to remove the PRIMARY KEY constraint then we can use ALTER TABLE statement as follows −
mysql> alter table Player DROP PRIMARY KEY; Query OK, 0 rows affected (0.31 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> DESCRIBE Player; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | ID | int(11) | NO | | NULL | | | Name | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.04 sec)
The above result set shows that PRIMARY KEY constraint on column ‘ID’ has been removed.
- Related Articles
- How can we remove FOREIGN KEY constraint from a column of an existing MySQL table?
- How can we remove composite PRIMARY KEY constraint applied on multiple columns of an existing MySQL table?
- How can we remove NOT NULL constraint from a column of an existing MySQL table?
- How can we apply the PRIMARY KEY constraint to the field of an existing MySQL table?
- Can we remove a primary key from MySQL table?
- How can we set PRIMARY KEY on multiple columns of an existing MySQL table?
- How can we add a FOREIGN KEY constraint to the field of an existing MySQL table?
- How can we apply a NOT NULL constraint to a column of an existing MySQL table?
- How can we remove a column from MySQL table?
- How can we apply UNIQUE constraint to the field of an existing MySQL table?
- How can I define a column of a MySQL table PRIMARY KEY without using the PRIMARY KEY keyword?
- Set existing column as Primary Key in MySQL?
- How can I drop an existing column from a MySQL table?
- How can we set PRIMARY KEY on multiple columns of a MySQL table?
- How can we drop UNIQUE constraint from a MySQL table?

Advertisements