gpt4 book ai didi

mysql - 如何让 UNIQUE 字段为空?

转载 作者:搜寻专家 更新时间:2023-10-30 23:27:30 26 4
gpt4 key购买 nike

我在数据库表中归档了条形码,该表是UNIQUE
但字段不是强制性的,所以我想将其留空。
我尝试将 null 放入,但这不是个好主意。
原因我使用的是 Hibernate,因此 hibernate.hbm.xml 不会生成包装类 Integer,它可能是:

<property name="barcode" type="java.lang.Integer">
<column name="barcode" />

所以上面的表达式允许插入null
相反,它生成如下 UNIQUE 字段:

<property name="barcode" type="java.lang.Integer">
<column name="barcode" unique="true" />

但是我在数据库表UNIQUEnullable 中创建了barcode
反正那也无济于事。

那么我怎样才能让它保持空白或以其他方式处理它。

最佳答案

null 表示缺少数据。在 UNIQUE 列中使用 null 是完全合理的,只要该列未同时设置为 NOT NULL

关于mysql - 如何让 UNIQUE 字段为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54656628/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com