本文涉及:MySQL的索引类型及区别和如何建立、删除、查看索引
索引类型
MySQL中的的索引分为单列索引和组合索引
普通索引
create index title_index ON book(title(100)); alter table book ADD index title_index(title);
如果是char、varchar类型,length可以小于字段实际长度。如果是blob和text类型,必须指定 length
唯一索引
与普通不同的是唯一索引列的值必须唯一,但允许有空值,不过空值也只能是存在一个
create unique index title_index ON book(title(100)); alter table book ADD unique index title_index(title);
主键索引
组合索引
create index title_author_index ON book(title(100),author(80)); alter table book ADD index title_author_index(title,author);
删除索引
drop index title_index ON book;
show index from book;