MySQL学习--唯一索引

唯一索引:就是创建索引时,限制索引的值必须唯一

 

1.在创建表时创建索引

create table emp(
ename varchar(20),
deptno int(10) primary key auto_increment,
unique 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 unique index index_niu on emp(deptno);
explain select * from emp where deptno=22;
 

3.alter table创建索引

alter table emp add unique index index_niu(deptno);

 

4.删除索引

drop index index_niu on emp;

posted @ 2023-08-05 20:02  飞虎就是我  阅读(75)  评论(0编辑  收藏  举报