如何从Mysql中的列中删除键?(primary,foreign,unique all)
这里我给了列 id
的主键ALTER TABLE table ADD PRIMARY KEY(id);
现在我想将其删除,并且不使用任何键列 id 是否有任何方式。我用过,
ALTER TABLE `table` MODIFY `id` INT
但实际上它给出了UNIQUE键
答案 0 :(得分:0)
您可以使用
ALTER TABLE `table` MODIFY `id` INT ;
ALTER TABLE `table` DROP PRIMARY KEY;
答案 1 :(得分:0)
您好,您可以运行以下命令:
Alter TABLE tableName
MODIFY COLUMN id INT,DROP PRIMARY KEY;
mysql> desc TestTable;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(10) | NO | PRI | NULL | |
| name | varchar(30) | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.05 sec)
mysql> ALTER TABLE TestTable MODIFY COLUMN id INT(10),DROP PRIMARY KEY;
Query OK, 0 rows affected (0.62 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc TestTable;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(10) | YES | | NULL | |
| name | varchar(30) | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)