sql - Why does an int column values defaults to '0' when passed empty? -
i have table integer column.
create table [dbo].[tble1]( [id] [int] not null, [test] [nchar](10) null )
when try insert values , pass empty string id column below, gets inserted , value of id column 0 default.
insert [dbo].[tble1] ([id],[test]) values ('','a')
i couldn't find satisfying reasoning behind it. 1 please share thoughts on this?
what happening ''
being converted integer. rules string can converted, based on digit characters in string.
if string empty, gets converted 0.
so, conversion happening @ "top" level. types don't match sql server attempts implicit conversion.
unfortunately, documentation not clear on topic:
character expressions being converted exact numeric data type must consist of digits, decimal point, , optional plus (+) or minus (-). leading blanks ignored. comma separators, such thousands separator in 123,456.00, not allowed in string.
to honest, interpret "must consist of digits" saying there must @ least 1 digit (although technically in english "zero" treated plural, don't think of plurals including 0 elements). however, empty string has been used -- pretty forever -- valid value type across broad range of databases.
Comments
Post a Comment