mysql索引之唯一索引


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

 

主鍵索引是特殊的唯一索引


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM