How to use ALTER TABLE Statement with DROP KEY Clause In MariaDB
In MariaDB, you can change an existing table’s structure with the ALTER TABLE statement. An existing index in a table can be selectively removed using the ALTER TABLE statement’s DROP KEY clause.
Syntax:
ALTER TABLE table_name DROP KEY index_name;
Replace table_name with the name of the table where the index is declared and index_name with the name of the index you wish to drop.
Example:
ALTER TABLE example_table DROP KEY email_index;
-- Showing the Indexes defined on example_table
SHOW INDEX FROM example_table;
Output:
Explanation: The above query remove the email_index Index defined on example_table.
Dropping an Index in MariaDB
In MariaDB, indexes play a crucial role in enhancing query performance by facilitating fast data access within a table. However, there are scenarios where you might need to drop indexes. This article explores various methods to drop indexes in MariaDB, including using DROP INDEX
, ALTER TABLE DROP INDEX
, and ALTER TABLE DROP KEY
statements. Additionally, it covers dropping a primary key index using ALTER TABLE DROP PRIMARY KEY
.
Contact Us