Does MySQL Workbench automatically create indexes for foreign keys?

与世无争的帅哥 提交于 2021-02-19 03:31:06

问题


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 index for me, knowing that I'm likely to be selecting against that column, and give it (confusingly) the same name as the foreign key?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5957353/does-mysql-workbench-automatically-create-indexes-for-foreign-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!