数据库中的空值
空值意味着
- 没有值
- 不适用、未分配、未知或不可用
哪一个是正确的?
Null value means
- No value
- Inapplicable,unassigned, unknown, or unavailable
Which is true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
空值意味着
哪一个是正确的?
Null value means
Which is true?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(12)
这完全取决于它的使用环境。 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.
它可以意味着任何这些事情(而且并不总是很明显),这是反对使用空值的一个论点。
请参阅: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
来自维基百科
From Wikipedia
显然,您拥有 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.
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.
SQL 语义支持的唯一答案是“未知”。 如果它意味着“无值”,那么
将返回 FALSE,但它返回 NULL。 这是因为表达式中的 NULL 值意味着未知值,而据系统所知,未知值很可能是“Hi There”。
The only answer supported by SQL semantics is "unknown." If it meant "no value," then
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.
NULL 表示字段尚未设置值,或者已被重新设置为 NULL。
它并非未知或不可用。
请注意,查找 NULL 值时,不要在 where 子句中使用“=”,而使用“is”,例如:
Not:
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.:
Not:
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.
Null 意味着什么都没有、未知、没有价值。
这并不意味着不可用或不适用。
Null means nothing, unknown and no value.
It does not mean unavailable or in applicable.
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.
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
全部 :-)
如果您想为字段添加语义,请添加 ENUM
all :-)
if you want to add a semantic meaning to your field, add an ENUM