MySQL学习--普通索引

发布时间 2023-08-05 20:01:17作者: 飞虎就是我


在创建表时创建索引,已有表创建索引,alter table创建索引

1.在创建表时创建索引

create table emp(
ename varchar(20),
deptno int(10) primary key auto_increment,
index index_niu(deptno)
);
explain select * from emp where deptno=22;
 
2.已有表创建索引
create table emp(
ename varchar(20),
deptno int(10) primary key auto_increment
);
create index index_niu on emp(deptno);
explain select * from emp where deptno=22;
 

3.alter table创建索引

alter table emp add index index_niu(deptno);