Thursday, March 8, 2012

Date format of 0000-00-00 or 00:00:00

I am converting a MySQL database to SQL server 2000. I noticed that in one of the database fields in a table, they set a default value for the field as 0000-00-00. Is this okay for a default value for SQL Server 2005 ? How about a default value of 00:00:00 ?

Will

'00:00:00' is ok, while '0000-00-00' is invalid. A quick test in SQL Server:

create table testDate (id int,t smalldatetime default '00:00:00')

insert into testDate(id) select 1


create table testDate1 (id int,t smalldatetime default '0000-00-00')

insert into testDate1(id) select 1

The 2nd insert will fail because '0000-00-00' is a date out of range. In SQL, there are some instructions when using datatime and smalldatetime data type, please refer to:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_9xut.asp

No comments:

Post a Comment