×

MySQL Drop Index

Sometimes we have an index that is not required in data operations. In that case, we can use this statement to remove an existing index from the table. We can delete single or multiple index columns from the table.

Syntax

The syntax of the delete index from the existing table is shown below.

ALTER TABLE table_name DROP INDEX index_name;

The syntax of the delete index from the table is shown below.

DROP INDEX index_name ON table_name [algorithm | lock];

The syntax of the delete index from the table with algorithm and lock types is shown below.

DROP INDEX index_name ON table_name [algorithm = {DEFAULT or INPLACE or COPY} |
Lock = {DEFAULT or NONE or SHARED or EXCLUSIVE} ];

The syntax of the delete primary index from the table is shown below.

DROP INDEX PRIMARY ON table name;

Algorithm

algorithm = { DEFAULT or INPLACE or COPY }
  • The algorithm assigns a particular algorithm to remove the table index.
  • The algorithm uses DEFAULT, INPLACE, and COPY clauses.
  • The COPY algorithm clause helps to copy a new table using each row.
  • The INPLACE clause allows rebuilding the table. This algorithm allows manipulating table statements.

Lock

Lock = {DEFAULT or NONE or SHARED or EXCLUSIVE}
  • The lock controls the level of reads and writes the table while the index is deleting from the table.
  • The lock has a DEFAULT, NONE, SHARED, and EXCLUSIVE option to remove the index column.
  • The default sets a high level of read and write index simultaneously.
  • The NONE lock allows read and write while deleting the index column. If the "none" lock does not allow, then the MySQL system shows an error.
  • The SHARED lock allows read concurrently. If you do not allow read coexistence, then the MySQL system shows an error.
  • The EXCLUSIVE lock access exclusive concurrent in the drop index query.

Examples of the delete index

1) Example: The basic delete index example shows below.

Execute the below query to delete unwanted indexes from the table. The index name and table name requires to delete the index.

mysql> drop index mark on index_table;

OUTPUT

Execute the below query to see the available index from the table.

mysql> show index from index_table;
MySQL Drop Index

In the above image, we can see that one row is removed from the table. The table shows the key name, column name, index type, visibility of the table.

2) Example: The basic delete index with database example shows below.

Execute the following query to delete the index from the available table. Here you will use the "alter" keyword with the "drop index" statement.

mysql> alter table index_table DROP index mark;

OUTPUT

Execute the below query to see the available index from the table.

mysql> show index from index_table;
MySQL Drop Index

In the above image, we can see that one row is removed from the table. The table shows the key name, column name, index type, visibility of the table.

3) Example: The basic delete index example with algorithm shows below.

Execute the following query to remove the index with an algorithm. Here, the query applies the INPLACE algorithm.

mysql> drop index mark on index_table algorithm = INPLACE;

OUTPUT

Execute the below query to see the available index from the table.

mysql> show index from index_table;
MySQL Drop Index

In the above image, we can see that one row is removed from the table. The table shows the key name, column name, index type, visibility of the table. The key name is an index name.

4) Example: The basic delete index with lock example shows below.

Execute the following query to remove the index with lock. Here, the query applies DEFAULT lock.

mysql> drop index mark on index_table LOCK = DEFAULT;

OUTPUT

Execute the below query to see the available index from the table.

mysql> show index from index_table;
MySQL Drop Index

In the above image, we can see that one mark is removed from the table. The table shows the key name (index name), column name, index type, unique key, and table visibility.

5) Example: The basic delete index with algorithm and lock example shows below.

Execute the following query to remove the index with algorithm and lock. Here, the query applies the DEFAULT algorithm and lock.

mysql> drop index mark on index_table algorithm = DEFAULT LOCK = DEFAULT;

OUTPUT

Execute the below query to see the available index from the table.

mysql> show index from index_table;
MySQL Drop Index

In the above image, we can see that the mark row is removed from the table. The table shows the critical name, column name, index type, visibility of the table.

6) Example: The delete index with different algorithms and lock examples show below.

Execute the following query to remove the primary index with algorithm and lock. Here, the query applies copy algorithm and none lock.

mysql> drop index mark on index_table algorithm = COPY LOCK = SHARED;

OUTPUT

Execute the below query to see the available index from the table.

mysql> show index from index_table;
MySQL Drop Index

The above output image removes the mark row from the table. The table shows the key name, column name, index type, visibility of the table. Here copy algorithm requires a lock; otherwise, the MySQL system shows an error.


Related Topics

MySQL database queries

MySQL database queries Database queries help to create, use, show and, delete the database. A Database is a collection of several tables and data. The database uses SQL language to perform...

3 minutes read.

MySQL Clauses

MySQL Clauses MySQL system clauses are keywords or statements to handle information. It helps to operate a group of the data and apply it to require conditions. The clauses apply conditions...

16 minutes read.

MySQL EQUI JOIN

An equijoin is an operation that combines multiple tables based on equality or matching column values in the associated tables. This operation links more than two tables based on a...

5 minutes read.

MySQL Database Introduction

MySQL - Database Introduction: The database plays an essential role in MySQL for storing and modifying the data. The database creates and keeps multiple tables. The database organizes and manipulates...

8 minutes read.

MySQL LOG() function

In this context, we will learn how we can use the MySQL LOG () function with proper syntax and good examples. Introduction of MySQL LOG() function The LOG() function in MySQL is...

3 minutes read.

MySQL PI() function

In this context, we will learn how we can use the MySQL PI() function with proper syntax and good examples. Introduction of MySQL PI() function PI() function in MySQL is used to...

2 minutes read.

MySQL Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 minutes read.

MySQL DATEDIFF() function

In this context, we will learn how we can use the MySQL DATEDIFF() function with proper syntax and good examples. Introduction of MySQL DATEDIFF() function DATEDIFF() function in MySQL is used to...

3 minutes read.

MySQL Operators

MySQL Operators MySQL operator needs advanced operation on the table and its data. This operator works with the "WHERE" clause. MySQL operators are a statement to modify information. It helps to...

13 minutes read.

MySQL LOCATE() function

In this context, we will learn how we can use the MySQL LOCATE() function with proper syntax and good examples. Introduction of MySQL LOCATE() function LOCATE() function in MySQL is used for...

3 minutes read.

MySQL Truncate() Function

In this context, we will learn how we can use the MYSQL TRUNCATE function to truncate a number to a mentioned number of decimal places. Syntax of MySQL Truncate Function A number...

2 minutes read.

MySQL DAY() function

In this context, we will learn how we can use the MySQL DAY() function with proper syntax and good examples. Introduction of MySQL DAY() function This function in MySQL is used to...

2 minutes read.

MySQL FLOOR() function

In this context, we will learn how we can use the MySQL FLOOR() function with proper syntaxes and examples. Introduction of MySQL Floor() function: FLOOR() function in MySQL is used to return...

3 minutes read.

MySQL Advance table Query

MySQL Advance table Query The table is created by index, rows, and columns in the MySQL database. The user saves their information in matrix format. The database requires a query to...

14 minutes read.

MySQL vs Oracle

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL LOG2() function

In this context, we will learn how we can use the MySQL LOG2() function to calculate the Logarithm of a specific number with base 2 with proper syntax and examples. Introduction...

2 minutes read.

MySQL PERIOD_DIFF() function

In this context, we will learn how we can use the MySQL PERIOD_DIFF() function with proper syntax and good examples. Introduction of MySQL PERIOD_DIFF() function This function in MySQL is used to...

2 minutes read.

MySQL REVERSE() function

In this context, we will learn how we can use the MySQL REVERSE() function with proper syntax and good examples. Introduction of MySQL REVERSE() function This function could be used to reverse...

2 minutes read.

MySQL AVG function

This function works on numerical data type values. The average function shows the average value of the data set. If an average function returns a null value, then the row...

5 minutes read.

MySQL LEAST function

This statement displays the smallest value of the table. The LEAST function returns a null value when the table contains a null value. If the table contains all numerical values,...

2 minutes read.