Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does dropping a table in MySQL also drop the indexes?

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.

like image 709
Teflon Ted Avatar asked May 20 '09 12:05

Teflon Ted


People also ask

Does dropping a table remove indexes?

Dropping a table removes the table definition from the data dictionary. All rows of the table are no longer accessible. All indexes and triggers associated with a table are dropped.

What happens when you drop a table in MySQL?

The DROP TABLE statement removes a table and its data permanently from the database. In MySQL, you can also remove multiple tables using a single DROP TABLE statement, each table is separated by a comma (,). The TEMPORARY option allows you to remove temporary tables only.

When you drop a table all indexes related to the table are also dropped?

All rows from the table are dropped. All table indexes and domain indexes are dropped, as well as any triggers defined on the table, regardless of who created them or whose schema contains them. If table is partitioned, then any corresponding local index partitions are also dropped.

Does DROP TABLE remove indexes SQL Server?

We use the SQL DROP Table command to drop a table from the database. It completely removes the table structure and associated indexes, statistics, permissions, triggers and constraints.


1 Answers

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.

like image 158
AvatarKava Avatar answered Oct 13 '22 17:10

AvatarKava