最好使用一个空值作为一个“”或者为NULL? [英] Is better use an empty value as a '' or as NULL?

查看:111
本文介绍了最好使用一个空值作为一个“”或者为NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据库架构

我有以下字段:


  • title(string)

  • subtitle

  • description(string)

最好将默认值设置为空字符串 NULL

Is better set the default value as an empty string '' or a NULL?

推荐答案

通常的合同是:


  • NULL 表示没有可用的信息。

  • <$ c

  • NULL means "no information available".
  • '' means "there is information available. It's just empty."

超出这一点自从 NULL 在任何语言中发明而不仅仅是SQL之后,还有许多哲学讨论。

Beyond this point there is much philosophical discussion since the invention of NULL in any language, not just SQL.

唯一的技术点这里是:在PostgreSQL NULL 可以比长度为零的字符串更有效地存储。如果这在你的情况真的很重要...我们不知道。

The only technical point here is: In PostgreSQL NULL can be stored more efficiently than a string of length zero. If that really matters in your case ... we cannot know.

这篇关于最好使用一个空值作为一个“”或者为NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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