Empty string and Default values

Often newbies use empty string and consider it as NULL. But when an empty string is passed, it may not be stored as empty string or NULL. It actually depends on the datatype of the column

Consider this example

DECLARE @t TINYINT,@s SMALLINT,@i INT,@big BIGINT,@f FLOAT,@bit BIT, @sm SMALLMONEY,@m MONEY,@d DATETIME

 

SELECT

@t='',

@i='',

@big='',

@f='',

@bit='',

@sm='',
@m='',

@d=''

SELECT
@t as tinyint_col,

@i as int_col,

@big as bigint_col,

@f as float_col,

@bit as bit_col,

@sm as smallmoney_col,

@m as money_col,

@d as datetime_col

 

The result is Zero for all the variables except @d which has the date value of 1900-01-01 00:00:00.000





So beware of this and always use NULL if you want NULL values stored in the column
and dont use empty string
Published 02 September 2008 10:21 by Madhivanan

Comments

No Comments