索引

使用索引可以加快查询速度

索引的原则

 数据量很大,且经常被查询的数据表可以设置索引

 索引只添加在经常被作为检索条件的字段上面

 不要在大字段上创建索引,字符串过长不适合添加索引

复制代码
use test;
#创建索引
create table t_message (
 id int unsigned primary key,
 content varchar(200) not null,
 type ENUM("公告","通报","个人通知") not null,
 create_time timestamp not null,
 index idx_type (type)
)character set = utf8;
#删除索引
drop index idx_type on t_message;
#添加索引
create index idx_type on t_message(type);
alter table t_message add index idx_type(type);
#查看索引信息
show index from t_message;
复制代码

 

posted @   南风知君  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示