如何在Mysql中为表行添加穆尔键?

iugsix8n  于 2023-02-15  发布在  Mysql
关注(0)|答案(1)|浏览(113)

我有一张这样的table:

+-------+---------+------+-----+---------+----------------+
| Field | Type    | Null | Key | Default | Extra          |
+-------+---------+------+-----+---------+----------------+
| id    | int(11) | NO   | PRI | NULL    | auto_increment |
| post  | int(11) | NO   |     | NULL    |                |
| liker | int(11) | NO   |     | NULL    |                |
+-------+---------+------+-----+---------+----------------+

我想将其更改为:

+----------+---------+------+-----+---------+----------------+
| Field    | Type    | Null | Key | Default | Extra          |
+----------+---------+------+-----+---------+----------------+
| id       | int(11) | NO   | PRI | NULL    | auto_increment |
| post_id  | int(11) | NO   | MUL | NULL    |                |
| liker_id | int(11) | NO   | MUL | NULL    |                |
+----------+---------+------+-----+---------+----------------+

我知道如何使用PHPMyAdmin更改字段名。但想知道如何添加MUL键到它们?

fcg9iug3

fcg9iug31#

您可以使用change column重命名列,并使用add index添加索引:

alter table TheTable change column post post_id int;
alter table TheTable change column liker liker_id int;
alter table TheTable add index(post_id);
alter table TheTable add index(liker_id);

按表名更改TheTable

相关问题