mysql如何创建索引、删除索引

本文共有611个字,关键词:

问题:mysql如何创建索引、删除索引?

解决:使用 create index 方法或者 alter table 方法

方法:

创建普通索引
create index school_id on user(school_id);
或者
alter table user add index school_id (school_id);

创建组合索引
create index name_age on user(name, age);
或者
alter table user add index name_age (name, age);
创建唯一索引
alter table user add unique (name);

创建主键索引
alter table user add primary key (id);

查询创建的索引

show index from user;

删除索引

drop index school_id on user;
或者
alter table user drop index school_id;
版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论