Does dropping a MySQL table automatically drop that table's indices too?
If a table is dropped, all associated indexes are dropped automatically. See Also: Oracle Database SQL Language Reference for syntax and restrictions on the use of the DROP INDEX statement.
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.
Indexes on variable-width columns of NDB tables are dropped online; that is, without any table copying. The table is not locked against access from other NDB Cluster API nodes, although it is locked against other operations on the same API node for the duration of the operation.
The DROP TABLE statement allows a table to be removed from a MySQL database. This statement deletes the entire structure as well as the content of the table.
Yes. It drops the indexes. This can be verified:
CREATE TABLE table1 (foo INT); CREATE INDEX ix_table1_foo ON table1 (foo); CREATE INDEX ix_table1_foo ON table1 (foo); -- fails: index already exists. DROP TABLE table1; CREATE TABLE table1 (foo INT); CREATE INDEX ix_table1_foo ON table1 (foo); -- succeeds: index does not exist.
You can also verify it by looking in the information schema:
CREATE TABLE table1 (foo INT); CREATE INDEX ix_table1_foo ON table1 (foo); SELECT COUNT(*) FROM information_schema.STATISTICS WHERE INDEX_NAME = 'ix_table1_foo'; -- returns 1 DROP TABLE table1; SELECT COUNT(*) FROM information_schema.STATISTICS WHERE INDEX_NAME = 'ix_table1_foo'; -- returns 0
Yes. Indices are part of their owner table and are freed along with the row data when dropped.
(Foreign-key indices on other tables that refer to it will prevent the table being dropped.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With