sql - Is it pointless to add a default value of NULL to a nullable field -
i have table used store configurable elements within system.
for simplicities sake assume table structure:
create table [dbo].[configuration_table] ( flag bit not null default 1, insert_datetime datetime not null default getdate(), update_datetime datetime default null)
when initial insert completed time of entry has set.
when update made, update date time set track when update flag occurred.
is pointless set default value on nullable field null?
in sql server there not advantage in doing that, because:
when omit nullable column field list of
insert
usenull
when no default constraint value defined:-- insert_datetime null when no default constraint defined on column insert configuration_table (flag, insert_datetime) values (1,'20171209')
if use keyword
default
value inserting default value usenull
when no constraint defined:-- insert_datetime null when no default constraint defined on column insert configuration_table (flag, insert_datetime, update_datetime) values (1,'20171209',default)
in fact, there small disadvantage in doing because column have unneeded dependency on constraint (for example, if column int
, want alter
column bigint
fail because of constraint).
so yes, it's pointless set default value on nullable field null
, @ least in sql server (maybe other rdbms have quirks made useful).
Comments
Post a Comment