У меня есть таблица вроде этого:
+-------+---------+------+-----+---------+----------------+
| 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
?
Вы можете переименовать столбцы с помощью 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
по имени вашей таблицы.