field in a table that get's updated every time a record is updated

  • is there a system level field that get updated for a table every time a row is updated?

  • sonal_anjaria (11/29/2012)


    is there a system level field that get updated for a table every time a row is updated?

    Not sure what you are looking for here exactly. There is nothing per row that gets updated when an update occurs that would indicate the row was updated.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • There is a row version value stored by the system, in order to deal with snapshots, but it's not something you have access to.

    If you need to track that kind of thing, add a RowVersion type column to the table. Data here: http://msdn.microsoft.com/en-us/library/ms182776.aspx

    If you need to know when a row was updated, then you're getting into audit trails (Change Data Capture, triggers, log parsers, et al), or at least a column with DateTime or DateTime2 or DateTimeOffset. If you use the added column, you'll need to modify code that updates the table so that it updates that column, or add a trigger to the table to handle the update. CDC (Change Data Capture) is easier and has much less of a performance hit than triggers, but is only available in Enterprise edition.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • No. SQL does not normally track that a row has changed.

    SQL will add columns that might be used to determine that when you specify certain things for a given table, such as replication, but SQL does not do it by default.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

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

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