SQL server record insertion timestamp?

Discussion in 'Databases' started by tbarr60, Aug 1, 2007.

  1. #1
    When a record is inserted into SQL Server, is there a timestamp built in? If I didn't create a column and insert a timestamp is there one available, maybe @@timestamp?
     
    tbarr60, Aug 1, 2007 IP
  2. saurabhj

    saurabhj Banned

    Messages:
    3,459
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't think so... You need to create a column...
     
    saurabhj, Aug 2, 2007 IP
  3. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Do you mean a timestamp or a datetime?

    In MS SQL timestamp isnt anything to do with the date or time but to do with the order in which modifications took place (see http://www.sqlteam.com/article/timestamps-vs-datetime-data-types)

    As far as I am aware there isnt really a log if you have forgotten to add the relevant column (though our SQL guy may correct me)

    You would need to have either a timedate or smalltimedate column with a default value of getdate()
     
    AstarothSolutions, Aug 2, 2007 IP
  4. flippers.be

    flippers.be Peon

    Messages:
    432
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Astaroth is correct, there's no timestamp kept
    (ok if you use transactional logging and go search into these files then... but that's not what you want)

    column with getdate() default is what you need to do
     
    flippers.be, Aug 2, 2007 IP
  5. Kommunicate

    Kommunicate Peon

    Messages:
    60
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You should probably just use a datetime or smalldatetime column for timestamps. SQL Servers timestamp type does not store datetime information at all but just a uniqueidentifier that changes when a row is created or updated. You can only have 1 timestamp column per table.

    Like flippers.be said, use getdate() as the column default. I like to user getutcdate() personally as a default.
     
    Kommunicate, Aug 3, 2007 IP
  6. tbarr60

    tbarr60 Notable Member

    Messages:
    3,455
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    210
    #6
    Thanks for the replies. The records I was wondering about are historic so I adding a column now wouldn't help. I don't really need the date data, i was just curious to see if there was a date in meta data.
     
    tbarr60, Aug 3, 2007 IP