我最初创建了一个这样的表:
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)?
发布评论