关键词

MySQL修改和删除索引(DROP INDEX)方法详解

修改索引

1.修改单个索引列:

ALTER TABLE table_name
MODIFY INDEX index_name(column_name_new);

2.修改多列组成的联合索引列:

ALTER TABLE table_name
DROP INDEX index_name,
ADD INDEX index_name(column_name_new1, column_name_new2);

实例:

例如有以下表:

CREATE TABLE employee (
 id INT PRIMARY KEY,
 first_name VARCHAR(50),
 last_name VARCHAR(50),
 age INT,
 salary INT,
 INDEX name_index(first_name, last_name)
);

现在需要将name_index中的first_name改为new_first_name:

ALTER TABLE employee
MODIFY INDEX name_index(new_first_name, last_name);

删除索引(DROP INDEX)

语法:

ALTER TABLE table_name
DROP INDEX index_name;

实例:

例如有以下表:

CREATE TABLE employee (
 id INT PRIMARY KEY,
 first_name VARCHAR(50),
 last_name VARCHAR(50),
 age INT,
 salary INT,
 INDEX name_index(first_name, last_name)
);

现在需要删除name_index索引:

ALTER TABLE employee
DROP INDEX name_index;

本文链接:http://task.lmcjl.com/news/18008.html

展开阅读全文