SQL Server NULL 和 DEFAULT 列规范
仅使用 Allow Nulls = Yes
声明列与同时使用 Default Value or Binding = NULL
和 Allow Nulls = Yes< 声明列有何区别/代码>?
我特别感兴趣的是 JDBC 和 wasNull 方法语义是否存在差异。我的印象是,Allow Nulls = Yes
(没有 DEFAULT 规范)足以允许您从 INSERT 子句中排除该列,并期望插入行中该字段的值被分配 SQL NULL 值...
有人向我建议,当我没有将 DEFAULT 显式指定为 NULL 时,wasNull 行为不当,特别是对于我的数据库中的 NVARCHAR 字段,该字段是使用结果集的 getString 方法从结果集中检索的...
Is there a difference between declaring a column with just Allow Nulls = Yes
as compared to declaring it with both Default Value or Binding = NULL
AND Allow Nulls = Yes
?
In particular I'm interested in if there is a difference with respect to JDBC and the wasNull method semantics. My impression was that Allow Nulls = Yes
(without a DEFAULT spec) was sufficient to allow you to exclude the column from an INSERT clause and expect that the value of that field in the inserted row is assigned the SQL NULL value...
It has been suggested to me that wasNull misbehaves for specifically for an NVARCHAR field in my database that is retrieved from a result set using the getString method of the result set when I didn't have the DEFAULT specified explicitly as NULL...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将列声明为默认值
NULL
,但这是一件毫无意义的事情。我期望它实现的只是稍微减慢插入过程(因为它必须查找默认值)。Allow Nulls = Yes
应该就足够了。我不明白
wasNull
具体是如何进入这个领域的,因为据我所知,wasNull
在使用结果集时使用,而不是在执行插入操作时使用。You can declare a column to have a default value of
NULL
, but it's a spectacularly pointless thing to do. All I'd expect it to achieve is to minutely slow down the insertion process (since it has to look up the default value).Allow Nulls = Yes
should be sufficient.I don't see how
wasNull
comes into this specifically, since, so far as I understand it,wasNull
is used when consuming result sets, not when performing insert operations.如果
INSERT
语句的列列表中未提供该值,则仅使列允许空值并不能保证其值为NULL
。联机丛书在参数 标题。查看
(column_list)
。Simply making the column allow nulls does not guarantee that it will have the value
NULL
if it is not provided in anINSERT
statement's column list.Books Online has the gory details under the Arguments heading. Look at
(column_list)
.