getdate()

  • 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.

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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