Generate timestamp

  • Hi

    Sorry, pretty new to SQL.

    I want to create a table with a timestamp column which is updated automatically if the record within the table is updated. What would be the best method on creating the table?

    Thanks in advance.

     

    Regards

    Raxso

  • You would have to write a trigger.

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Assumption: You mean a datetime/datetime2 type and not the timestamp data type (which is just a synonym for rowversion) -- a guid-like value used for versioning.

    If you are in an environment where you can ensure the table is only updated via a stored procedure, do it there.

    If you cannot ensure all application updates update the Modified column, or you or others sometimes update the data via TSQL, then a trigger is probably the most certain.

    Unfortunately, unlike MySQL, SQL Server does not have an auto-update capability for datetime.

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

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