×

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 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 Queries

MySQL Queries MySQL supports SQL queries in the MySQL interface. These queries help to interact data with the application. MySQL uses create database, user database, create a table, truncate table, and...

13 minutes read.

MySQL Table Query

MySQL table query A database stored a lot of data and divided them into different relations known as tables. Each database can contain more than one table. These tables are created...

7 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 LN() function

In this context, we will learn how we can use the MySQL LN() function with proper syntax and good examples. Introduction of MySQL LN() function For evaluation of the natural logarithm of...

2 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.

MySQL MONTHNAME() function

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

3 minutes read.

MySQL LOG10() function

In this context, we will learn how we can use the MySQL LOG10() function with proper syntax and good examples. Introduction of MySQL LOG10() function To evaluate the natural logarithmic value of...

2 minutes read.

MySQL HEX() function

In this context, we will learn how we can use the MySQL HEX() function with proper syntax and good examples. Introduction of MySQL HEX() function For returning an equivalent hexadecimal string value...

3 minutes read.

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 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 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 Unique index

It helps to maintain data integrity to enforce the uniqueness of values in one or more columns. We can create more than one UNIQUE index in a single table, which...

3 minutes read.

MySQL CROSS JOIN

MySQL CROSS JOIN combines all possibilities of the two or more tables and returns the result that contains every row from all contributing tables. It links several columns from the...

4 minutes read.

MySQL Character Length Function

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

2 minutes read.

MySQL NOW() function

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

2 minutes read.

MySQL FORMAT() function

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

2 minutes read.

MySQL String Function

The string function is used to maintain and operate string values. This function modifies the string data as per function. We can do the concatenation, conversion, removal and replacing the...

4 minutes read.

MySQL Join

The relational database system needs to interconnect multiple tables with each other. MySQL is a popular and easy data management system to connect multiple tables. The foreign key is used...

5 minutes read.

MySQL ROUND() function

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

3 minutes read.