auto populate DateInserted field

  • I have a table,

    CREATE TABLE [dbo].[HaHa](

    [PNR] [varchar](20) NULL,

    [Date] [varchar](20) NULL,

    [GDS] [varchar](20) NULL,

    [BookingPCC] [varchar](100) NULL)

    I need to add a DateInserted column, so I alter the table.

    ALTER TABLE HaHa

    ADD DateInserted datetime NOT NULL DEFAULT getdate()

    GO

    Now the table looks like this:

    CREATE TABLE [dbo].[TRANS_AQUAWL](

    [PNR] [varchar](20) NULL,

    [Date] [varchar](20) NULL,

    [GDS] [varchar](20) NULL,

    [BookingPCC] [varchar](100) NULL,

    [DateInserted] [datetime] NOT NULL DEFAULT (getdate())

    )

    The problem is that, no matter what day or what time, the DateInserted column is being populated with '1977-07-07 00:00:00.000'. Please help me understand where I went wrong. Why isn't the DateInserted column being populated with the current date?

  • How do you do your insert statement?

    The insert statement should not have DateInserted field, then table will populate the current datetime in that field.

  • Very good question, I have no idea how the data is inserted as it is done by a third party application. 'They' have no knowledge of the new DateInserted column, so one would think that a value would not be provided. I have traced the database in question and still can't figure out how data is being inserted into the table.

  • SqlProfiler could be the means to determine how the data is being inserted into your table.

    Especially if you have a test environment to weed out the normal course of queries hitting the database.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply