MySQL Tutorial

MySQL Tutorial MySQL Features MySQL Database Introduction MySQL Environmental Setup MySQL Data Types MySQL variable MySQL Advance table Query MySQL database queries MySQL Entity-Relationship Model MySQL Table Query MySQL Operators MySQL logical conditions MySQL Queries MySQL Clauses Clustered vs Non-Clustered Index MySQL Full text index MySQL Descending Index MySQL Invisible Index MySQL Composite Index MySQL Prefix index MySQL Index MySQL Create index MySQL Drop Index MySQL Show index MySQL Unique index MySQL Table MySQL Variable MySQL View MySQL Constraints MySQL Command Line Client Basic Queries MySQL Stored Procedure MySQL IF Statement MySQL Subquery MySQL Triggers

MySQL Join

MySQL Join MySQL CROSS JOIN MySQL DELETE JOIN MySQL EQUI JOIN MySQL INNER JOIN MySQL Union MySQL NATURAL JOIN MySQL RIGHT JOIN MySQL SELF JOIN MySQL UPDATE JOIN

MySQL Function

MySQL Function MySQL AVG() Function MySQL SUM() Function MySQL String() Function MySQL Advance() Function MySQL Aggregate() Function MySQL COALESCE() Function MySQL Control Flow Function MySQL COUNT() Function MySQL Date And Time Function MySQL GREATEST() Function MySQL ISNULL() Function MySQL LEAST() Function MySQL Math() Function MySQL MAX() Function MySQL MIN() Function MySQL find_in_set() function MySQL ASIN() Function MySQL CEIL() function MySQL CEILING() function MySQL TAN() Function MySQL Truncate() Function MySQL FLOOR() function MySQL LN() function MySQL LOG2() function MySQL LOG10() function MySQL MOD() function MySQL PI() function MySQL POW() function MySQL RADIANS() function MySQL RAND() function MySQL ROUND() function MySQL Character Length Function MySQL Current Date Function MySQL Date Add Function MySQL Date Format Function MySQL Datediff Function MySQL Day Function MySQL Elt Function MySQL Export Set Function MySQL Field Function MySQL Format Function MySQL From Base64 Function MySQL Hex Function MySQL Insert Function MySQL Instr Function MySQL Length Function MySQL CONCAT() function MySQL FIND_IN_SET() function MySQL LIKE() function MySQL LOAD_FILE() function MySQL LOCATE() function MySQL LOG() function MySQL MONTHNAME() function MySQL NOW() function MySQL PERIOD_ADD() function MySQL PERIOD_DIFF() function MySQL POWER() function MySQL QUARTER() function MySQL REVERSE() function MySQL RIGHT() Function MySQL RPAD() function MySQL RTRIM() function MySQL SEC_TO_TIME() function MySQL SOUNDEX() function

Questions

Which Clause is Similar to Having Clause in MySQL

Misc

MySQL Error 1046 - No Database Selected Failed to Start MySQL Service Unit MySQL Service Unit not Found Import MySQL Connector Mudule not Found Error No Module Named MySQL Joins Available in MySQL MySQL Docs MySQL Download For Windows 7 64 Bit MySQL Error Code 1064 MySQL Export MySQL History MySQL Host MySQL Import MySQL Drop All Tables MySQL Drop MySQL Error Code 1175 MySQL Events MySQL Except MYSQL Foreign Key Constraint MySQL If Exists MySQL IndexOf MySQL List All Tables json_extract in MySQL TIMESTAMPDIFF in MySQL MySQL Syntax Checker Sudo MySQL Secure Installation

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.