在MySQL中刪除主鍵需要兩步.
(1)如果有auto_increment,先刪除之;
(2)刪除主鍵約束 primary key
1、alter table table1 modify id int(11);
mysql> desc table1;
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| name | char(20) | NO | | NULL | |
| age | char(33) | NO | | NULL | |
+-------+----------+------+-----+---------+----------------+
#在這里指定id的新類型為int,其他的如自增,自然是刪掉了。。
mysql> alter table table1 modify id int;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc table1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int | NO | PRI | NULL | |
| name | char(20) | NO | | NULL | |
| age | char(33) | NO | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)
2、alter table t9 drop primary key;
#刪除主鍵
mysql> alter table table1 drop primary key;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc table1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int | NO | | NULL | |
| name | char(20) | NO | | NULL | |
| age | char(33) | NO | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)
本文摘自 :https://www.cnblogs.com/