创建普通索引:
create index index_c_user_profile_id on instrument(c_user_profile_id)
alter table instrument add index index_c_user_profile_id(c_user_profile_id)
创建唯一索引:
create unique index index_c_user_profile_id on instrument(c_user_profile_id)
alter table instrument add unique index_c_user_profile_id(c_user_profile_id)
删除索引:
drop index index_name on station
查看索引:
show index from station
show keys from station
注:
1.text类型字段不能创建索引
会报错:1170 - BLOB/TEXT column ‘description’ used in key specification without a key length
2.创建唯一索引不能插入该列已有数据,如果该列已有相同数据,则不能创建唯一索引
会报错:1062 - Duplicate entry ‘s1001’ for key ‘index_model_number’
sql语句截取create_time的年月日:
date_format(s.create_time,'%Y-%m-%d') = '2021-04-01'