Modify, and delete MySQL index (DROP INDEX)

In MySQL can modify the index, and then create an index with the same name as required by deleting the original index, enabling the operation to modify the index.

 

The basic syntax

When the index is no longer needed, you can use the DROP INDEX statement or ALTER TABLE statement to delete the index.

1) DROP INDEX statement

Syntax:

DROP INDEX <index name> ON <table name>

Syntax is as follows:

  • <索引名>: Index name to be deleted.
  • <表名>: Specifies the index name of the table.

2) Use the ALTER TABLE statement

According to the syntax of ALTER TABLE statement shows that the statement can also be used to remove the index. Specific use is part of the syntax specified ALTER TABLE statement is one of the following clause.

  • DROP PRIMARY KEY: represents the main key to delete the table. A table has only one primary key is a primary key index.
  • DROP INDEX index_name: means to delete an index named index_name.
  • DROP FOREIGN KEY fk_symbol: means to delete the foreign key.

Note: If you delete a column is an integral part of the index, so when you delete the column, the column will be deleted from the index; if all the columns make up the index are removed, the entire index will be deleted.

Delete Index

[Example 1] Remove tb_stu_info index table, SQL statements and input the execution result is shown below.

  mysql> DROP INDEX height      -> ON tb_stu_info;  Query OK, 0 rows affected (0.27 sec)  Records: 0  Duplicates: 0  Warnings: 0  mysql> SHOW CREATE TABLE tb_stu_infoG  *************************** 1. row ***************************         Table: tb_stu_info  Create Table: CREATE TABLE `tb_stu_info` (    `id` int(11) NOT NULL,    `name` char(45) DEFAULT NULL,    `dept_id` int(11) DEFAULT NULL,    `age` int(11) DEFAULT NULL,    `height` int(11) DEFAULT NULL  ) ENGINE=InnoDB DEFAULT CHARSET=gb2312  1 row in set (0.00 sec)

[Example 2] Remove the name of the table id tb_stu_info2 index, SQL statements, and input the execution result is shown below.

  mysql> ALTER TABLE tb_stu_info2      -> DROP INDEX height;  Query OK,
Published 44 original articles · won praise 1 · views 10000 +

Guess you like

Origin blog.csdn.net/mysqlsd/article/details/103474797