Is there any way to make a UNIQUE index case insensitive in Mysql 5.1.x ?

前端 未结 3 1666
抹茶落季
抹茶落季 2020-12-30 11:06

If so - What must change in this table ?

CREATE TABLE  contestants 
( 
  idContestants  int(10) unsigned NOT NULL AUTO_INCREMENT,
  idEvent        int(10) un         


        
相关标签:
3条回答
  • 2020-12-30 11:34

    If you mean case sensitive then:

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

    If you mean case insensitive then:

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

    For table level do (for case insensitive):

    ALTER TABLE `contestants` DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci
    

    Note that table level only affects new columns.

    For database level do (for case insensitive):

    ALTER DATABASE `database_name` CHARACTER SET latin1 COLLATE latin1_general_ci
    

    Note that database level only affect new tables.

    0 讨论(0)
  • 2020-12-30 11:35

    Yes, use a case-insensitive collation on the columns involved.

    MySQL Manual :: Column Character Set and Collation

    0 讨论(0)
  • 2020-12-30 11:35

    This worked for me in Mysql 5.5

    ALTER TABLE `contestants` MODIFY
    `ContestantName` VARCHAR(50) 
    CHARACTER SET latin1
    COLLATE latin1_bin;
    
    0 讨论(0)
提交回复
热议问题