Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2009
    Posts
    8

    Unanswered: create a column for a table which displays when record was created

    I want to create a column in an existing table which demonstrates when a record was created.

    I have tried using the GetDate() and GetUTCDate() methods but everytime I refresh, they ONLY display the current system date for all records.

    How do I achieve this?

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Add a datetime column. Set the default value of the column to Getdate().
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by blindman
    Add a datetime column. Set the default value of the column to Getdate().
    did they change that in SQL 2005 or SQL 2008?

    because you couldn't do that before...
    Only a constant value, such as a character string; a system function, such as SYSTEM_USER(); or NULL can be used as a default.
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jul 2009
    Posts
    8
    thanks for that, I have managed to work it perfectly!!

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Getdate() has been an acceptable default as long as I can remember. Certainly back to SQL Server 2000, and I think 7.0 as well. Not sure about 6.5.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by blindman
    Certainly back to SQL Server 2000...
    wha?

    i want a second opinion
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I can confirm that it works on 6.5 (well, compatability 65)
    George
    Home | Blog

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    wait, wait....

    in the immortal words of phil mickelson, i am such an idiot

    sorry, i misinterpreted BOL (quoted above)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    phil mickelson called you an idiot? Prestigious!
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •