本文介绍了数据库:我可以在第三个正常表单数据库中有可空属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可空的 winnerID 属性,根据拍卖的出价不断更新。



属性设置为节省某个时间到底计算谁赢得了拍卖。但这个值最初为null。



这会违反第三范式吗?我知道1NF的规则4声明我不能有null属性,但是注释说这是一个有争议的声明。



你能澄清一下吗?谢谢!

解决方案

在SQL中定义空值的方式 - 作为无法与域值比较的非值 - 意味着它们违反1NF(和所有较高的法线形式)。关系(由规范化表格表示的数学结构)对于每一行的每一列必须具有单个值。 Null表示我们没有值,可空列表示我们在一个表中有两个关系 - 一个超类型关系,包括除了可空的一个列之外的所有列,以及一个具有相同主键和先前可空列的子类型关系,我们只能记录属性已知的行。归一化的目的是将数据集因素化为基本事实而不丢失信息,因此在单个表中具有两个关系与目标相矛盾,并使诸如关系代数/微积分这样的事情更加复杂。


$ b $正常形式是形式的逻辑定义结构,而不是可以适应情况的工业最佳实践,因此我没有看到太多争议的空间。是否应该使用它们以及如何处理它们是一个更有趣的话题。



当null违反正常形式时,这并不意味着你不能使用null在你的SQL数据库。他们有风险和好处。我也使用它们,但要考虑。


I have a nullable winnerID attribute which is constantly updated according to the bidding of an auction.

This attribute is set to save sometime in the end to calculate who won the auction. But this value is null initially.

Will this violate Third Normal Form? I knew Rule 4 of 1NF states that I cannot have nullable attribute, but the note says this is a controversial statement.

May you please clarify this for me? Thank you!

解决方案

The way nulls are defined in SQL - as non-values which can't be compared with domain values - means they violate 1NF (and all higher normals forms). A relation (the mathematical structure represented by normalized tables) must have a single value for every column for every row. Nulls mean we have no value, and a nullable column means we have two relations in one table - a supertype relation which includes all the columns except the nullable one, and a subtype relation which has the same primary key and the previously nullable column, for which we can record only rows for which the attribute is known. The purpose of normalization is to factor a data set into elementary facts without losing information, so having two relations in a single table contradicts the objective and makes things like relational algebra/calculus more complicated.

The normal forms are formal logically defined structures, not industrial best practices which can be adapted to the situation, so I don't see much space for controversy. Whether we should use them and how they should be handled is a more interesting topic.

While nulls violate the normal forms, it doesn't mean you can't use nulls in your SQL database. They have risks as well as benefits. I use them too, but with consideration.

这篇关于数据库:我可以在第三个正常表单数据库中有可空属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:04