将列添加到现有多列索引

use*_*174 4 mysql indexing

在我的表中,我有一个列的多列索引(名称,文件夹)

我最近添加了一个名为date的新列,我想在其中添加一个索引,但我想把它放到现有的多列索引中

我什么时候Alter table books add index theindex (date); 得到Duplicate key name 'theindex'

如何在不创建新密钥的情况下向索引添加其他列?

Pra*_*man 10

只需将语法更改为以下方式即可向索引添加新列:

ALTER table `books` DROP INDEX theindex;
ALTER table `books` ADD INDEX theindex (`date`, `time`);
Run Code Online (Sandbox Code Playgroud)

  • 在旧版本中,在同一个"ALTER"中同时执行"DROP"和"ADD"的速度是原来的两倍. (2认同)