在为空的情况下的功能依赖性 [英] Functional dependencies in case of nulls

查看:34
本文介绍了在为空的情况下的功能依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个包含3列A,B和C列的表

Suppose we have a table with 3 columns A,B and C

A      B      C
---------------
1      2      3
2      4      5
4      6      7
n      5      n

这里的"n"表示空.

我们可以说A-> B和A-> C吗?我知道功能依赖项的定义,但在使用空值的情况下我感到困惑.

Can we say that A -> B and A -> C? I know the definition of functional dependencies but I'm just confused in the case of null values.

推荐答案

如果将null视为值,则答案为是. A->B,C 保存在给定的数据中.但是,要成为一个值会带来某些要求.所有适用于该域(例如整数)的运算符(例如相等,加法,小于等)必须在存在null的情况下进行良好定义.

If null is considered a value, then the answer is yes. A -> B, C holds in the given data. However, to be a value imposes certain requirements. All operators applicable to the domain (e.g. integers) like equality, addition, less than, and so on, must be well-defined in the presence of nulls.

如果null不是值,则答案更为复杂.严格来说,功能依赖关系适用于关系.如果表代表关系,那么我们可以在表中引用功能依赖项.但是,表示缺少值的符号是元数据,而不是数据.它允许用单个表表示多个联合不兼容的关系.在这种情况下,我们无法将函数依赖的概念应用于表,因为不清楚我们在谈论哪种关系.

If null is not a value, then the answer is more complicated. Functional dependencies, strictly speaking, apply to relations. If a table represents a relation, then we can refer to functional dependencies in the table. However, a symbol that represents the absence of a value is metadata, not data. It allows multiple union-incompatible relations to be represented by a single table. In this case, we can't apply the concept of functional dependency to the table since it's not clear which relation we're talking about.

更令人困惑的是,SQL DBMS无法一致地处理null.在某些情况下,它们的处理方式类似于值,而在其他情况下,其处理方式则是缺少值.如果要逻辑地理解和描述表,最好的选择是将其分解为一组无空的关系,然后分别分析每个部分.

Further confusing things, SQL DBMSs don't handle nulls consistently. In some cases, they're handled like values, in others like the absence of values. If you want to understand and describe a table logically, the best option is to decompose it into a set of null-free relations, and then to analyze each of those parts independently.

对于您的示例表,如果null不是值,我们就会遇到问题.最后一行没有唯一的标识符(因为另一行也有 B:4 ,所以它不能是 B:4 ),我们无法从缺少的内容中确定任何内容信息.在不丢弃该行的情况下,无法将示例分解为一组关系.

In the case of your example table, we run into a problem if null isn't a value. The last row has no unique identifier (it can't be B:4 since another row has B:4 as well) and we can't determine anything from a lack of information. The example can't be decomposed into a set of relations without discarding that row.

如果我们将最后一行更改为具有 B:5 ,则将其分解为两个关系: R1 = {(A:1,B:2,C:3),(A:2,B:4,C:5),(A:4,B:6,C:7)} R2 = {(B:2),(B:4),(B:6),(B:5)} .我们可以说 A->B,C 保留在R1中,但不保留在R2中.

If we change the last row to have B:5 instead, then we decompose it into two relations: R1 = {(A:1, B:2, C:3), (A:2, B:4, C:5), (A:4, B:6, C:7)} and R2 = {(B:2), (B:4), (B:6), (B:5)}. We can say A -> B, C holds in R1 but not in R2.

这篇关于在为空的情况下的功能依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆