Heim  >  Artikel  >  Datenbank  >  mysql索引之唯一索引_MySQL

mysql索引之唯一索引_MySQL

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

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`);

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn