Home > Database > Mysql Tutorial > mysql索引之唯一索引_MySQL

mysql索引之唯一索引_MySQL

WBOY
Release: 2016-05-30 17:11:08
Original
1690 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template