Home >Database >Mysql Tutorial >Experience sharing about index operations in Mysql
Indexes do not depend on storage space. If used properly, they can improve query efficiency.
This article will show the addition and deletion operations of indexes
1. Query on mysql Index information
Command:
show index from staff; Output: mysql> show index from staff; Empty set (0.00 sec)
2. Add a common index
Command:
create index idx_staff on staff(id);
3. Add UNIQUE index
Command:
create unique index idx_unique_staff on staff(id);
Tips:
You cannot use the CREATE INDEX statement to create a PRIMARY KEY index
4. Add the index through the alter command
Command:
alter table staff add index idx_staff_byAlter (id);
5. Delete index
Command 1:
drop index idx_staff on staff;
6. Command 2 :
alter table staff drop index idx_staff_byAlter;
The above is the detailed content of Experience sharing about index operations in Mysql. For more information, please follow other related articles on the PHP Chinese website!