有没有办法在Mysql 5.1.x中使UNIQUE索引不区分大小写?

如果是这样 – 这张桌子必须改变什么?

CREATE TABLE  contestants 
( 
  idContestants  int(10) unsigned NOT NULL AUTO_INCREMENT,
  idEvent        int(10) unsigned NOT NULL,
  ContestantName  varchar(50) DEFAULT NULL,
  PRIMARY KEY (idContestants),
  UNIQUE KEY Index_UniqueName (idEvent,ContestantName),
)
ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
如果你的意思是区分大小写的话

ALTER TABLE `contestants` CHANGE `ContestantName` `ContestantName` VARCHAR( 50 )
CHARACTER SET latin1 COLLATE latin1_bin NULL DEFAULT NULL 

如果你的意思是不区分大小写,那么:

ALTER TABLE `contestants` CHANGE `ContestantName` `ContestantName` VARCHAR( 50 )
CHARACTER SET latin1 COLLATE latin1_general_ci NULL DEFAULT NULL 

对于表级别do(不区分大小写):

ALTER TABLE `contestants` DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci

请注意,表级仅影响新列.

对于数据库级别do(不区分大小写):

ALTER DATABASE `database_name` CHARACTER SET latin1 COLLATE latin1_general_ci

请注意,数据库级别仅影响新表.

翻译自:https://stackoverflow.com/questions/6888279/is-there-any-way-to-make-a-unique-index-case-insensitive-in-mysql-5-1-x

转载注明原文:有没有办法在Mysql 5.1.x中使UNIQUE索引不区分大小写?