July 2, 2009 at 11:20 am
I have table with date column in it for which getdate() is the default value but when i insert data i did insert date column by explicitly forcing getdate() function with in the script and there was no error
but i would like to know how sql server reacts when 2 getdate() functions executed for 1 column.
July 2, 2009 at 11:42 am
the default value for a column is used only if the column was not referenced in the insert.
if you include the column and it's value in the insert, the default is ignored and your value is used.
that's important, because if you explicitly insert NULL into a column with a default, the default would not get used, which is typically not what someone wants.
here's a quick and dirty example:
create table #example(exampleId int identity(1,1) primary key,
exampletext varchar(30),
exampleflag char(1) default 'T',
exampledate datetime default getdate())
insert into #example(exampletext,exampleflag,exampledate)
SELECT null,null,null
union all
select 'val','F',getdate() -7
insert into #example(exampletext,exampleflag)
select 'val','F'
insert into #example(exampletext)
select .val2'
select * from #example
Lowell
July 2, 2009 at 2:00 pm
Tara, are you kidding us ... Why cant you test the same ?
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply