gpt4 book ai didi

mysql - MySQL 中允许空值的唯一约束

转载 作者:行者123 更新时间:2023-11-29 21:05:16 25 4
gpt4 key购买 nike

我有一个存储产品代码的字段。代码是唯一的,但有些产品根本没有代码。我无法发明代码,因为那些是提供商代码。

这种约束在 MySQL 中可能吗?

我是存储过程和触发器的菜鸟,因此如果解决方案涉及其中之一,请耐心等待。

更新:该列不为空。这就是为什么我无法做到这一点。

最佳答案

是的,你可以做到这一点。请参阅MySQL reference (version 5.5) .

A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. For all engines, a UNIQUE index allows multiple NULL values for columns that can contain NULL.

关于mysql - MySQL 中允许空值的唯一约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36875891/

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