SQL Server Datetime NULL value

别等时光非礼了梦想. 提交于 2019-12-24 08:49:04

问题


I want to insert values into a SQL Server table, but every time I get

"Cannot insert the value NULL into column 'ddod'" error.

[ddod] [datetime] NOT NULL

I'm not inserting NULL value, but 0000-00-00 00:00:00.000, because no datetime was chosen.

Is 0000-00-00 00:00:00.000 the same as NULL?

Thanks a lot for help


回答1:


'0000-00-00 00:00:00.000' is not a valid datetime

select CAST('0000-00-00 00:00:00.000' as datetime)

gives the following error

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

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)

In that case it gets cast to NULL instead.

Is there any reason you are not using NULL anyway to represent the absence of a value rather than a "magic" sentinel value?



来源:https://stackoverflow.com/questions/7674101/sql-server-datetime-null-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!