索引

################
####索引
################

#####.普通索引
#####.唯一性索引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;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值