Sqlite NULL和唯一?

Sqlite NULL和唯一?,第1张

概述我注意到我可以在具有UNIQUE约束的列中具有NULL值:UNIQUE(col) 在某些情况下会产生任何问题吗? 虽然以下内容涉及多个空值,但它不涉及与此类设计相关的任何“问题”,而不是可能的数据库/ SQL可移植性 – 因此它应该不被认为是答案,仅供参考. 这实际上在SQLite常见问题解答中.它是一种设计选择 – SQLite(与SQL Server不同)选择多个NULL值不计入索引中的唯一性 我注意到我可以在具有UNIQUE约束的列中具有NulL值:UNIQUE(col)

在某些情况下会产生任何问题吗?

虽然以下内容涉及多个空值,但它不涉及与此类设计相关的任何“问题”,而不是可能的数据库/ sql可移植性 – 因此它应该不被认为是答案,仅供参考.

这实际上在sqlite常见问题解答中.它是一种设计选择 – sqlite(与sql Server不同)选择多个NulL值不计入索引中的唯一性.

The SQL standard requires that a UNIQUE constraint be enforced even if one or more of the columns in the constraint are NULL,but SQLite does not do this. Isn’t that a bug?

Perhaps you are referring to the following statement from sql92:

A unique constraint is satisfIEd if and only if no two rows in a table have the same non-null values in the unique columns.

That statement is ambiguous,having at least two possible interpretations:

A unique constraint is satisfIEd if and only if no two rows in a table have the same values and have non-null values in the unique columns.

A unique constraint is satisfIEd if and only if no two rows in a table have the same values in the subset of unique columns that are not null.

sqlite follows interpretation (1),as does Postgresql,MysqL,Oracle,and Firebird. It is true that Informix and Microsoft sql Server use interpretation (2),however we the sqlite developers hold that interpretation (1) is the most natural reading of the requirement and we also want to maximize compatibility with other sql database engines,and most other database engines also go with (1),so that is what sqlite does.

见comparison of NULL handling.

总结

以上是内存溢出为你收集整理的Sqlite NULL和唯一?全部内容,希望文章能够帮你解决Sqlite NULL和唯一?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1160668.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存