是否有理由在可空列上指定 DEFAULT (NULL)?

编程入门 行业动态 更新时间:2024-10-22 21:38:26
本文介绍了是否有理由在可空列上指定 DEFAULT (NULL)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最初创建了一个这样的表:

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)?

本文发布于:2023-11-29 08:29:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645873.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有理由   可空列上   NULL   DEFAULT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!