在ANSI SQL 标准中unique 有两种实现方式

  1、是可以插入多个空值、也就是说多个null值看成是互不相同的。

  2、是只可以插入一个空值,也主是说把所有的空值看也是相同的。

在SQL Server  |  MySQL 中实现的是第二种标准。

例子:(代码以SQL server 的语法为例)

  create table tmp(x int primary key , y int );

  alter table   tmp add constraint unique_cons unique(y);

  insert into tmp(x,y) values(1,null); 

  insert into tmp(x,y) values(2,null);  这里就不行了 也就是说当插入第二个null 时两个null 会被当成同一个值。 

相关文章:

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