################
####索引
################
#####.普通索引
#####.唯一性索引unique
#####.全文索引fulltext(只能在char varchar text)
#####.单列索引 多列索引 空间索引(spatial)
############1.创建表示创建索引
-- [unique/fulltext/ /spatial] index [别名][(属性名 [(长度)] [asc/desc])
create table fruitshop.food(
fdid int,
fname varchar(20),
fdtype varchar(20),
index(fdid)); -- 普通索引
create table fruitshop.food(
fdid int,
fname varchar(20),
fdtype varchar(20),
unique index fdid_unique(fdid asc)); -- 唯一性索引
create table fruitshop.food(
fdid int,
fname varchar(20),
fdtype varchar(20),
fulltext index gname(fname)); -- 全文索引
create table fruitshop.food(
fdid int,
fname varchar(20),
fdtype varchar(20),
index(fdid,fname)); -- 多列索引
##############2.在现有表中创建索引
-- 方法一(不建议)create [unique/fulltext/ /spatial] index 索引名 on 表名 (属性名 [(长度)] [asc/desc])
create index name on fruitshop.food(fname);
-- 方法2(建议)alter table 表名 add [unique/fulltext/ /spatial] index 索引名 (属性名 [(长度)] [asc/desc])
alter table fruitshop.food add index name(fname);
############3.修改索引 (先删除再添加)
-- drop index 索引名 on 表名;
drop index name on fruitshop.food;
############4.查询当前表中起作用的索引
explain select * from fruitshop.food where id = 1;