1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #普通索引(index 另一个名字normal)、 #唯一索引(unique)、 #全文索引(fulltext)、 #空间索引(SPATIAL)
unique key email(email(10)) #使用索引长度 alter table 表名 add index 索引名(字段名) #添加普通索引 alter table 表名 drop index 索引名 #删除索引 show index from 表名 #查看索引
create table a1( name char(5), email char(15), key name(name), unique key email(email) );
#多列索引 create table a3( name char(5), email char(15), key name(name), unique key name_email(name,email) ); explain select * from a3 WHERE name="张"; # 分析sql alter table a1 add unique(name); # 添加唯一索引 alter table a1 add index index_name(email) #添加普通索引 alter table a1 drop index index_name #删除索引 show index from a1 \G #查看索引
|