Are UNIQUE indices case sensitive in MySQL?
-
19-08-2019 - |
Question
Are indices (indexes) defined as UNIQUE case sensitive in MySQL?
Solution
It depends on the collation of the field - if it's ci (case insensitive) or cs (case sensitive). The unique index would apply accordingly.
OTHER TIPS
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
There's nothing special about UNIQUE indexes - they follow the same case options as other indexes.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow