Does dropping a table in MySQL also drop the indexes?(在 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.
推荐答案
是的,确实如此.
但是,如果您有外键约束(例如 RESTRICT)来确保与其他表的参照完整性,则您需要在删除或截断表之前删除这些键.
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.
这篇关于在 MySQL 中删除表也会删除索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MySQL 中删除表也会删除索引吗?


基础教程推荐
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01