Heim >Datenbank >MySQL-Tutorial >探讨:sql插入空,默认1900-01-01 00:00:00.000的解决方法详解_MySQL

探讨:sql插入空,默认1900-01-01 00:00:00.000的解决方法详解_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:24:392439Durchsuche

bitsCN.com

sql2005 若字段定义的类型为datetime,插入为''(空),那么会默认值为1900-01-01 00:00:00.000

解决方法查询的时候过滤下cast(nullif('','') as datetime)

select cast('' as datetime)
    , cast(nullif('','') as datetime)
    , isnull(cast(nullif('','') as datetime),getdate())
/*
----------------------- ----------------------- -----------------------
1900-01-01 00:00:00.000 NULL                    2009-02-25 17:18:15.140

(1 行受影响)

*/

bitsCN.com
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn