如果你在mysql有唯一约束的列上插入两行值'A'和'a',Mysql会认为它是相同的,而在oracle中就不会。就是mysql默认的字段值不区分大小写?这点是比较令人头痛的事。

请看下面的测试:

mysql> create table test4(nick varchar(20) primary key);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into test4 values('A');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test4 values('a');
ERROR 1062: Duplicate entry 'a' for key 1

而如何设置让其列值区分大小写呢?

mysql> create table test4(nick varchar(20) binary primary key);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into test4 values('A');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test4 values('a');
Query OK, 1 row affected (0.00 sec)


在声明字符类型后,在后面加一个binary,mysql就可以区分大小写了。

相关文章:

  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2022-02-05
  • 2021-12-31
猜你喜欢
  • 2021-10-14
  • 2021-07-27
  • 2021-08-14
  • 2022-12-23
  • 2021-12-16
相关资源
相似解决方案