How do I rename an Index in MySQL

前端 未结 3 1048
一整个雨季
一整个雨季 2020-12-08 12:44

I would like to rename an index. I\'ve looked at the alter table documentation, but I can\'t figure out the syntax to simply rename an index. When doing it through the MyS

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 13:06

    This question was asked ages ago, and was last updated over half a year ago. Still I feel the need to add this tip:

    If the indexed column is used elsewhere as a foreign key, you may encounter an error related to that. Doing this may help:

    SET FOREIGN_KEY_CHECKS = 0;
    ALTER TABLE tbl DROP INDEX index_name;
    ALTER TABLE tbl ADD INDEX new_index_name (indexed_column);
    SET FOREIGN_KEY_CHECKS = 1;
    

    Hope someone finds this useful.

提交回复
热议问题