Does dropping a table in MySQL also drop the indexes?

MysqlDatabaseIndexingSql Drop

Mysql Problem Overview

It's not explicitly mentioned in the documentation ( I ask because I just saw a curious database migration in a Rails project where the developer was removing all the indexes before dropping the table, and that seemed unnecessary.

Mysql Solutions

Solution 1 - Mysql

Yes, it does.

However, if you have foreign key constraints such as RESTRICT that ensure referential integrity with other tables, you'll want to drop those keys prior to dropping or truncating a table.

Solution 2 - Mysql

Yes it would drop the index. There's no reason to keep the index if the underlying table isn't there. I suspect that the downward migration is just doing the opposite of the upward migration on a one-to-one basis.

Solution 3 - Mysql

It is unneccessary. Your DROP TABLE might however be prevented when the table is part of foreign key relationships and dropping your table would break the dependencies.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTeflon TedView Question on Stackoverflow
Solution 1 - MysqlAvatarKavaView Answer on Stackoverflow
Solution 2 - MysqltvanfossonView Answer on Stackoverflow
Solution 3 - MysqlDaniel SchnellerView Answer on Stackoverflow