zoukankan      html  css  js  c++  java
  • MySQL的UNIQUE KEY对数据中字母的大小写不敏感

    今天遇到一个坑,对于下列这样一个表:

    CREATE TABLE `test3` (
      `id` int(11) NOT NULL,
      `name` char(20) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    它的数据如下:

    +----+------+
    | id | name |
    +----+------+
    |  1 | aaa  |
    |  2 | Aaa  |
    +----+------+

    现在我想在这个表上的name字段加一个唯一索引,发现无法创建:

    root:test_4> alter table test3 add unique index uniq_name(name);
    ERROR 1062 (23000): Duplicate entry 'aaa' for key 'uniq_name'

    发现UNIQUE KEY对字母的大小写不敏感,具体原因现在还没查到,查到解决方法如下:

    root:test_4> alter table test3 add unique index uniq_name(name);
    Query OK, 0 rows affected (0.01 sec)
    Records: 0  Duplicates: 0  Warnings: 0

    也就是将name列的类型由varchar改为varchar binary类型,这样就可以解决了。

    具体原因待后续查找。

  • 相关阅读:
    修改css样式+jq中的效果+属性操作+元素操作
    案例1:点击菜单显示相应的图片
    jq容易混淆点
    jQuery中的选择器
    JQ基本
    arguments的使用
    函数方法
    forEach遍历
    数组中常用的方法
    数组 Array
  • 原文地址:https://www.cnblogs.com/lifewithlight/p/6027553.html
Copyright © 2011-2022 走看看