开发者

Does MySQL Workbench automatically create indexes for foreign keys?

When I create a foreign key in MySQL workbench, a new entry appears on the "Indexes" tab with the exact same same as the foreign key that I just created.

Is this actually the foreign key, showing up on the "Indexes" tab for some reason? Or does MySQL Workbench try to be helpful and create an ind开发者_运维百科ex for me, knowing that I'm likely to be selecting against that column, and give it (confusingly) the same name as the foreign key?


It's MySQL doing that, not workbench.
And yes, it is being helpful to create an index when you create a foreign key constraint.


Foreign keys in innodb require an index or a prefix of an index with the same fields as the constraint in the same order. It seems MySQL Workbench automatically creates these since they appear in the SQL script exported from MySQL Workbench. This is helpful but the problem is that it does not recognize the prefix from other indexes so it always creates an index even when it is unnecessary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜