是否有理由在可空列上指定 DEFAULT (NULL)? [英] Is there a reason to specify DEFAULT (NULL) on a nullable column?
问题描述
我最初创建了一个这样的表:
I have a table created like this originally:
CREATE TABLE dbo.XX (
YY int DEFAULT(NULL)
)
如果您这样做,然后在稍后编写表的脚本,您将获得以下代码,以及一个随机命名的默认约束:
If you do this, and then script the table later on, you will get the following code, plus a randomly named default constraint:
CREATE TABLE [dbo].XX([YY] [int] NULL)
GO
ALTER TABLE [dbo].XX ADD DEFAULT (NULL) FOR [YY]
GO
现在在列上指定 DEFAULT (NULL)
而不是一开始就将其保留为 [YY] [int] NULL
有什么实际意义吗?
Now is there any real point in specifying DEFAULT (NULL)
on a column instead of just leaving it as [YY] [int] NULL
in the first place?
推荐答案
无需向可空列添加 DEFAULT(NULL)
.
如果未向此类列提供数据,则它们将具有 NULL
.
If data is not supplied to such columns, they will have a NULL
.
我看到的唯一好处是 Larry Lustig 在他对这个问题的评论中发布的 - 它记录了您没有忘记为可空列添加默认值这一事实.
The only benefit I see is the one Larry Lustig has posted in his comment to the question - it documents the fact that you have not forgotten to add a default to the nullable column.
这篇关于是否有理由在可空列上指定 DEFAULT (NULL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!