Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6541583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:07:20+00:00 2026-05-25T11:07:20+00:00

I have a table in my SQL Server 2008 R2 database, and would like

  • 0

I have a table in my SQL Server 2008 R2 database, and would like to add a column called LastUpdated, that will automatically be changed every time the row is updated. That way, I can see when each individual row was last updated.

It seems that SQL Server 2008 R2 doesn’t have a data type to handle this like earlier versions did, so I’m not sure of the best way to do it. I wondered about using a trigger, but what would happen when the trigger updated the row? Will that fire the trigger again, etc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:07:21+00:00Added an answer on May 25, 2026 at 11:07 am

    To know which row was last updated, you need to create a new column of type DATETIME/DATETIME2 and update it with a trigger. There is no data type that automatically updates itself with date/time information every time the row is updated.

    To avoid recursion you can use the UPDATE() clause inside the trigger, e.g.

    ALTER TRIGGER dbo.SetLastUpdatedBusiness 
    ON dbo.Businesses 
    AFTER UPDATE -- not insert!
    AS
    BEGIN
        IF NOT UPDATE(LastUpdated)
        BEGIN
            UPDATE t
                SET t.LastUpdated = CURRENT_TIMESTAMP -- not dbo.LastUpdated!
                FROM dbo.Businesses AS t -- not b!
                INNER JOIN inserted AS i 
                ON t.ID = i.ID;
        END
    END
    GO
    

    In modern versions you can trick SQL Server into doing this using temporal tables:

    • Maintaining LastModified Without Triggers

    But this is full of caveats and limitations and was really only making light of multiple other similar posts:

    • A System-Maintained LastModifiedDate Column
    • Tracking Row Changes With Temporal
      Columns
    • How to add “created” and “updated” timestamps without triggers
    • Need a datetime column that automatically updates
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in a SQL Server 2005 database with a trigger that
Lets say I have a table in a sql server 2000 database called TransactionType:
SQL Server 2008 Database Question. I have 2 tables, for arguments sake called Customers
i have a table with jobs like this in a MS SQL Server 2008
I have a couple of tables in a SQL 2008 server that I need
I have a table in SQL server that has the normal tree structure of
I have a table in SQL Server 2000 Standard Edition called dbo.T668 (don't blame
I have a History Table in SQL Server that basically tracks an item through
In a SQL server database, I have a table which contains a TEXT field
On MS SQL Server 2005, I have a table that I want to replace.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.