Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2004
    Posts
    76

    Unanswered: equvialent for MySQLs On UPDATE clause

    MySQL has a ON UPDATE clause which can be used as given below:

    create table t(col1 varchar(90), time_col timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP);

    Whenever a column (col1) is updated time_col will also be updated with curren time stamp. Is there any equivaent in SQL Server

    Am aware that this could be handled using Triggers, is there any other better solution.
    Last edited by cheeku; 09-27-06 at 04:44.

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    you want use a default constraint that uses the GETDATE() function most likely.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The ON UPDATE clause is one of the convenient, but non-standard extensions that MySQL has brought to SQL. I don't think that Microsoft SQL implements that extension (other than via a trigger).

    -PatP

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by Thrasymachus
    you want use a default constraint that uses the GETDATE() function most likely.
    That would be on INSERT

    You need a trigger, or an application that only access the data through stored procedures, and they would have to be coded that way

    MOO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Create a trigger to do this.
    If it's not practically useful, then it's practically useless.

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

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Hire someone, and have them create a trigger for you
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    I think you can do this with a function.
    ..... oh wait no - it's a trigger
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i would say use a trigger
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Hire a Consulting firm, that will outsource to Bangalore, to create a trigger, then increase your QA staff to make sure the trigger is working correctly
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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