DESCRIBEPlayer;+-------+-------------+ ------+-----+---------+-------+|Field|Type |Null|Key|Default|Extra|+----- --+-"/> DESCRIBEPlayer;+-------+-------------+ ------+-----+---------+-------+|Field|Type |Null|Key|Default|Extra|+----- --+-">

Home >Database >Mysql Tutorial >How can we remove PRIMARY KEY constraint from column of existing MySQL table?

How can we remove PRIMARY KEY constraint from column of existing MySQL table?

WBOY
WBOYforward
2023-09-01 17:45:061037browse

我们如何从现有 MySQL 表的列中删除 PRIMARY KEY 约束?

We can remove PRIMARY KEY constraints from columns of existing tables by using DROP keyword and ALTER TABLE statement.

Example

Suppose we have a table "Player" with a primary key constraint on the "ID" column 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 delete PRIMARY KEY constraint, then we can use ALTER TABLE statement as shown below-

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 the PRIMARY KEY constraint on column "ID" has been deleted.

The above is the detailed content of How can we remove PRIMARY KEY constraint from column of existing MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:MySQL program overviewNext article:MySQL program overview