Home  >  Article  >  Database  >  mysql索引之唯一索引_MySQL

mysql索引之唯一索引_MySQL

WBOY
WBOYOriginal
2016-05-30 17:11:081616browse

mysql 的唯一索引一般用于不重复的字段,一般会把表中的id设为唯一索引,创建唯一索引的目的不是为了提高查询速度,而是为了避免数据重复,注意:唯一索引可以有多个,但是列值必须唯一,创建唯一索引使用关键字unique。

 

创建唯一索引

 

1,创建表的时候创建索引:

 

create table temp2(id int(10) not null auto_increment,title varchar(10) not null,cnt int(10) not null,primary key(`id`),index(`title`),unique key cnt(`cnt`)) engine=myisam;

 

 

2,添加索引

 

create unique index title on article(`title`);

 

3,

 

alter table article add index content(`content`);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn