数据库中的空值

发布于 2024-07-25 10:07:04 字数 78 浏览 3 评论 0原文

空值意味着

  1. 没有值
  2. 不适用、未分配、未知或不可用

哪一个是正确的?

Null value means

  1. No value
  2. Inapplicable,unassigned, unknown, or unavailable

Which is true?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

Hello爱情风 2024-08-01 10:07:04

这完全取决于它的使用环境。 null 表示没有值,但其原因取决于使用它的域。 在许多情况下,您列出的项目都是 null 的有效用途。

It's all about the context in which it's used. A null means there is no value but the reason for this will depend on the domain in which it is being used. In many cases the items you've listed are all valid uses of a null.

坠似风落 2024-08-01 10:07:04

它可以意味着任何这些事情(而且并不总是很明显),这是反对使用空值的一个论点。

请参阅:http://en.wikipedia.org/wiki/Null_(SQL)#争议

It can mean any of those things (and it is not always obvious which), which is one argument against using nulls at all.

See: http://en.wikipedia.org/wiki/Null_(SQL)#Controversy

待"谢繁草 2024-08-01 10:07:04

来自维基百科

Null 是一个特殊标记,用于
结构化查询语言 (SQL)
表明数据值不
存在于数据库中。 介绍者
关系数据库的创建者
模型、EF Codd、SQL Null 用于
满足全部真实的要求
关系数据库管理系统
(RDBMS)支持表示
“信息缺失且不适用
信息”。科德还介绍了
使用小写希腊欧米茄 (ω)
数据库中表示 Null 的符号
理论。 NULL也是SQL保留
用于识别 Null 的关键字
特殊标记。

From Wikipedia

Null is a special marker used in
Structured Query Language (SQL) to
indicate that a data value does not
exist in the database. Introduced by
the creator of the relational database
model, E. F. Codd, SQL Null serves to
fulfill the requirement that all true
relational database management systems
(RDBMS) support a representation of
"missing information and inapplicable
information". Codd also introduced the
use of the lowercase Greek omega (ω)
symbol to represent Null in database
theory. NULL is also an SQL reserved
keyword used to identify the Null
special marker.

断爱 2024-08-01 10:07:04

显然,您拥有 null 含义的数据库定义,但是对于应用程序来说,它可以意味着任何内容。 我曾经开发过一个奇怪的应用程序(免责声明 - 我没有设计它),它在连接表中使用 null 来表示所有选项(据称它的设计方式是为了“节省空间”)。 这是用于用户和角色管理的数据库设计。

因此,本例中的 null 意味着用户具有所有角色。 这就是日常的 WTF。 :-)

像许多人一样,我倾向于在实际可能的情况下避免使用空值。

Obviously you have the DB definition of what null means, however to an application it can mean anything. I once worked on a strange application (disclaimer- I didn't design it), that used null in a junction table to represent all of the options (allegedly it was designed this way to "save space"). This was a DB design for user and role management.

So null in this case meant the user was in all roles. That's one for daily WTF. :-)

Like many people I tend to avoid using nulls where realistically possible.

信仰 2024-08-01 10:07:04

null 表示数据库中不存在数据值,从而表示缺少信息。

还允许三路真值; 真、假、未知。

null indicates that a data value does not exist in the database, thus representing missing information.

Also allows for three-way truth value; true, false and unknown.

╰沐子 2024-08-01 10:07:04

SQL 语义支持的唯一答案是“未知”。 如果它意味着“无值”,那么

'Hi there' = NULL

将返回 FALSE,但它返回 NULL。 这是因为表达式中的 NULL 值意味着未知值,而据系统所知,未知值很可能是“Hi There”。

The only answer supported by SQL semantics is "unknown." If it meant "no value," then

'Hi there' = NULL

would return FALSE, but it returns NULL. This is because the NULL value in the expression means an unknown value, and the unknown value could very well be 'Hi there' as far as the system knows.

唠甜嗑 2024-08-01 10:07:04

NULL 表示字段尚未设置值,或者已被重新设置为 NULL。
并非未知或不可用。

请注意,查找 NULL 值时,不要在 where 子句中使用“=”,而使用“is”,例如:

select * from User where username is NULL;

Not:

select * from User where username = NULL;

NULL is a representation that a field has not had a value set, or has been re-set to NULL.
It is not unknown or unavailable.

Note, that when looking for NULL values, do not use '=' in a where clause, use 'is', e.g.:

select * from User where username is NULL;

Not:

select * from User where username = NULL;
念三年u 2024-08-01 10:07:04

NULL,在关系模型中,意味着未知。 它是一个标记,而不是在 SQL 中任何可以出现值的地方出现的值。

NULL, in the relational model, means Unknown. It's a mark that appears instead of a value wherever a value can appear in SQL.

你丑哭了我 2024-08-01 10:07:04

Null 意味着什么都没有、未知、没有价值。

这并不意味着不可用或不适用。

Null means nothing, unknown and no value.

It does not mean unavailable or in applicable.

滥情空心 2024-08-01 10:07:04

Null 是行中列的可测试状态,但它本身没有值。

例如:

int 只能是 ...,0,1,2,3,... 也可以是 NULL。

日期时间只能是有效日期...也可以是 NULL。

一个位只能是 0 或 1...也可以是 NULL。

varchar 可以是字符串...也可以是 NULL。

看到图案了吗?

您可以将列设为 NOT NULL,以便强制列采用值。

Null is a testable state of a column in a row, but it has no value itself.

By example:

An int can be only ...,0,1,2,3,... and also NULL.

An datetime can be only a valid date... and also NULL.

A bit can be only 0 or 1... and also NULL.

An varchar can be a string... and also NULL.

see the pattern?

You can make a column NOT NULL-able so that you can force a column to take a value.

终陌 2024-08-01 10:07:04

NULL SQL 关键字用于表示缺失值或不适用于关系表的值

The NULL SQL keyword is used to represent either a missing value or a value that is not applicable in a relational table

玉环 2024-08-01 10:07:04

全部 :-)
如果您想为字段添加语义,请添加 ENUM

create TABLE myTable
  (
  myfield varchar(50)
  myfieldType enum ('OK','NoValue','InApplicable','Unassigned','Unknown','Unavailable') NOT NULL
  )

all :-)
if you want to add a semantic meaning to your field, add an ENUM

create TABLE myTable
  (
  myfield varchar(50)
  myfieldType enum ('OK','NoValue','InApplicable','Unassigned','Unknown','Unavailable') NOT NULL
  )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文