Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Posts
    22

    Unanswered: mssql computed column

    I'm a newbie at MS-SQL, have always worked with MySQL. I'm working on a project and one of the tables I'm trying to get the date filled in automatically when the record is created. Here is my table structure:

    Code:
    item_id     int
    item_title  nchar(100)
    item_desc   text
    item_date    datetime
    I'm trying to set the 'item_date' field automatically when I insert a record. Example:

    Code:
    insert into forsale (item_title, item_desc) values ('item 1', 'item 1 description')
    I want the date field to automatically fill itself in with the current date. I've tried to put 'getdate()' as the Computed Column Specification but it is not working.

    Again I'm a newbie at MSSQL so any help would be appreciated.

    Thanks

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Don't make it a computed column. Just set getdate() as the default.
    If it's not practically useful, then it's practically useless.

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

  3. #3
    Join Date
    Sep 2003
    Posts
    22
    Thanks a lot!! Can't believe I overlooked something so simple LOL

  4. #4
    Join Date
    Jul 2006
    Posts
    22
    You may try also "inserting" the current date:

    Code:
    insert into forsale (item_title, item_desc,item_date) values ('item 1', 'item 1 description',getdate())

Posting Permissions

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