SQL Server Datetime NULL值 [英] SQL Server Datetime NULL value
问题描述
我想将值插入到SQL Server表中,但每次获得
I want to insert values into a SQL Server table, but every time I get
无法将值NULL插入列 ddod'错误。
"Cannot insert the value NULL into column 'ddod'" error.
[ddod] [datetime] NOT NULL
我没有插入NULL值,但 0000-00-00 00:00:00.000
,因为没有选择日期时间。
I'm not inserting NULL value, but 0000-00-00 00:00:00.000
, because no datetime was chosen.
是 0000-00-00 00:00:00.000
与NULL相同?
非常感谢帮助
推荐答案
p> '0000-00-00 00:00:00.000'
不是有效的 datetime
select CAST('0000-00-00 00:00:00.000' as datetime)
给出以下错误
将varchar数据类型转换为datetime数据类型导致
超出范围值。
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
您有以下选项关闭吗? / p>
Do you have the following options off?
set arithabort off
set ansi_warnings off
select CAST('0000-00-00 00:00:00.000' as datetime)
在这种情况下,它被转换为 NULL
In that case it gets cast to NULL
instead.
有没有什么理由你没有使用 NULL
反正代表没有价值而不是魔术哨兵值?
Is there any reason you are not using NULL
anyway to represent the absence of a value rather than a "magic" sentinel value?
这篇关于SQL Server Datetime NULL值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!