关系数据库中的空值好吗? [英] Are nulls in a relational database okay?

查看:34
本文介绍了关系数据库中的空值好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种观点认为,关系数据库中不允许出现空值.也就是说,表的属性(列)不应允许空值.来自软件开发背景,我真的不明白这一点.似乎如果 null 在属性的上下文中有效,则应该允许它.这在 Java 中很常见,其中对象引用通常为空.没有丰富的数据库经验,我想知道我是否在这里遗漏了什么.

There's a school of thought that null values should not be allowed in a relational database. That is, a table's attribute (column) should not allow null values. Coming from a software development background, I really don't understand this. It seems that if null is valid within the context of the attribute, then it should be allowed. This is very common in Java where object references are often null. Not having an extensive database experience, I wonder if I'm missing something here.

推荐答案

反对空值的一个论点是它们没有明确定义的解释.如果字段为空,则可以解释为以下任何一项:

One argument against nulls is that they don't have a well-defined interpretation. If a field is null, that could be interpreted as any of the following:

  • 值为Nothing"或Empty set"
  • 没有对该字段有意义的值.
  • 值未知.
  • 尚未输入该值.
  • 该值为空字符串(对于不区分空字符串和空字符串的数据库).
  • 某些特定于应用程序的含义(例如,如果值为 null,则使用默认值.")
  • 发生错误,导致该字段在不应该出现的情况下具有空值.

一些模式设计者要求所有值和数据类型都应该有明确定义的解释,因此空值是不好的.

Some schema designers demand that all values and data types should have well-defined interpretations, therefore nulls are bad.

这篇关于关系数据库中的空值好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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