problem with DEFAULT (getdate())

Hi all

I create table and set default value detdate(). But after insert record date display ‘1900-01-01 00:00:00’.

Example this,

CREATE TABLE [tblTemp1] (

ItemUserDate [smalldatetime] NOT NULL CONSTRAINT [DF_tblTemp1_ItemUserDate] DEFAULT (getdate())

)

GO

INSERT INTO dbo.tblTemp1 values(0)

select ItemUserDate from dbo.tblTemp1 =‘1900-01-01 00:00:00’

select getdate() =’2006-07-20 15:53:27.820’ I need this answer


Answer this question

problem with DEFAULT (getdate())

  • sapo

    Hi,

    try this:

    CREATE TABLE [tblTemp1] (

    part1 char,

    ItemUserDate [smalldatetime] NOT NULL CONSTRAINT [DF_tblTemp1_ItemUserDate] DEFAULT (getdate())

    )

    GO

    INSERT INTO dbo.tblTemp1 part1, values('a')

    And then do your select. You'll recieve the correct answer.

    You have you result because you're putting 0 in your default column, so default has no effect anymore...

    Greeting.



  • Yeshwanth HV

    thanks NB2006


  • Shadi_05

    thankx Stefan Haeck



  • furjaw

    Hi

    To make Insert work for the table structure with a single datetime column you can use Default VALUES option: INSERT INTO dbo.tblTemp1 DEFAULT VALUES


  • problem with DEFAULT (getdate())