Using examples to illustrate how to view, delete, and add indexes, first create a table, as follows:
Mysql> CREATE TABLE Stu (
ID int,
, name char (5),
Key name (name),
Unique key ID (ID)
);
1. View the index of the table (two methods)
(1) Show index from table name;
(2) Show create table table name;
2. Delete the index of the table (two methods)
(1) ALTER TABLE name DROP INDEX name
After deletion, look at the index, the index name ID is deleted, only the name index,
(2) Drop index index name on table name
3. Add Index
ALTER TABLE name ADD [index,unique] Index name (column name), as
(1) Add a unique index to the ID column and view the table index
(2) Add a normal index to the Name column, and then view the table index
4. Finally operation of the primary key index
(1) Add primary KEY index: ALTER TABLE name add primary key (column name);
(2) Delete primary KEY index: ALTER TABLE name drop PRIMARY key;
MySQL Learning note-index action statement