mysql索引

创建索引注意事项:

1、只能在表的列上创建索引

2、索引会加快查询速度,但是会影响更新的速度,因为要维护索引

3、索引并不是越多越好,要在频繁查询的where后的条件列上创建索引

4、小表或者唯一值极少的列上不建议建立索引,通常在大表以及不同内容多的列上建立索引


1、创建主键索引

alter table test change id id int primary key auto_increment


2、删除主键索引

alter table test drop primary key


3、创建普通索引 

index_dept:索引名称

dept(8)对字段dept的前8个字符建立索引

alter table test add index index_dept(dept)

alter table test add index index_dept(dept(8))

create index index_dept on test(dept(8))


4、根据多列建立联合索引

create index index_name_dept on student(name,dept)


5、删除普通索引

alter table test drop index index_dept

drop index index_dept on test

你可能感兴趣的:(mysql索引)