Last post Mar 16, 2020 01:06 AM by oned_gk
Mar 14, 2020 08:53 AM|uniservice3|LINK
Mar 14, 2020 10:42 AM|mgebhard|LINK
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?
Mar 14, 2020 11:07 AM|uniservice3|LINK
Mar 14, 2020 11:40 AM|mgebhard|LINK
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.
Mar 16, 2020 01:06 AM|oned_gk|LINK
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