locked
How to access edited previous rows in sql database RRS feed

  • Question

  • User836525179 posted
    Hi guys
    I need to access old rows before edit in sqlserver database
    I have that database in my sql server but i dont know how to see old rows
    Saturday, March 14, 2020 8:53 AM

All replies

  • User475983607 posted

    Hi guys
    I need to access old rows before edit in sqlserver database
    I have that database in my sql server but i dont know how to see old rows

    What is an "old row" in your SQL design?

    Saturday, March 14, 2020 10:42 AM
  • User836525179 posted
    records than i edited or updated
    Saturday, March 14, 2020 11:07 AM
  • User475983607 posted

    records than i edited or updated

    Once the update is committed the record is changed.  There's no mechanism in SQL server that automatically saves the "old row"  in a place that is easily fetched. It is up to you - the developer - to write code that meets your "old data" requirement.

    There's an OUTPUT clause that you can use to get the DELETED record during an UPDATE.    You can write code to store the "old data" in another table or logically archive the record; https://docs.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql?view=sql-server-ver15

    If you are trying to recover lost data then you'll need to restore from a backup.

    Saturday, March 14, 2020 11:40 AM
  • User-1716253493 posted

    Im not sure about your requirement.

    In sql you can have timestamp colomn, it's binary value.

    When you insert, update the data timespan value become biggest value because it's increament value.

    When you sort the data by timespan desc, last updated row will be at the top.

    SELECT TOP(1) * FROM YOURTABLE ORDER BY TSCOL DESC

    Another way, usualy in web form or sp you can keep the id of the row

    Monday, March 16, 2020 1:06 AM