在 MySQL 中删除表也会删除索引吗?
文档中没有明确提及(http://dev.mysql .com/doc/refman/6.0/en/drop-table.html)。 我问这个问题是因为我刚刚在 Rails 项目中看到了一个奇怪的数据库迁移,其中开发人员在删除表之前删除了所有索引,这似乎没有必要。
It's not explicitly mentioned in the documentation (http://dev.mysql.com/doc/refman/6.0/en/drop-table.html). 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,它确实。
但是,如果您有外键约束(例如 RESTRICT)来确保与其他表的引用完整性,则您需要在删除或截断表之前删除这些键。
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.
是的,它会删除索引。 如果基础表不存在,则没有理由保留索引。 我怀疑向下迁移只是在一对一的基础上做与向上迁移相反的事情。
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.
这是没有必要的。 然而,当表是外键关系的一部分并且删除表会破坏依赖关系时,您的 DROP TABLE 可能会被阻止。
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.