Are UNIQUE indices case sensitive in MySQL?

这一生的挚爱 提交于 2020-01-22 17:03:16

问题


Are indices (indexes) defined as UNIQUE case sensitive in MySQL?


回答1:


It depends on the collation of the field - if it's ci (case insensitive) or cs (case sensitive). The unique index would apply accordingly.




回答2:


You can make a column case-sensitive by using this syntaxis. the unique index also will be case-sensitive.

ALTER TABLE tbl_name MODIFY
col_name column_definition
[CHARACTER SET charset_name]
[COLLATE collation_name]

Example:

ALTER TABLE `tablename` MODIFY
`column` VARCHAR(100) 
CHARACTER SET utf8
COLLATE utf8_bin;

Note: utf8_bin compares strings by the binary value of each character in the string.

Tested on Msql 5.5.X




回答3:


There's nothing special about UNIQUE indexes - they follow the same case options as other indexes.



来源:https://stackoverflow.com/questions/463764/are-unique-indices-case-sensitive-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!