Last post Mar 16, 2020 01:06 AM by oned_gk
Member
303 Points
255 Posts
Mar 14, 2020 08:53 AM|uniservice3|LINK
All-Star
53121 Points
23673 Posts
Mar 14, 2020 10:42 AM|mgebhard|LINK
uniservice3 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?
Mar 14, 2020 11:07 AM|uniservice3|LINK
Mar 14, 2020 11:40 AM|mgebhard|LINK
uniservice3 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.
52683 Points
15721 Posts
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
Member
303 Points
255 Posts
How to access edited previous rows in sql database
Mar 14, 2020 08:53 AM|uniservice3|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
All-Star
53121 Points
23673 Posts
Re: How to access edited previous rows in sql database
Mar 14, 2020 10:42 AM|mgebhard|LINK
What is an "old row" in your SQL design?
Member
303 Points
255 Posts
Re: How to access edited previous rows in sql database
Mar 14, 2020 11:07 AM|uniservice3|LINK
All-Star
53121 Points
23673 Posts
Re: How to access edited previous rows in sql database
Mar 14, 2020 11:40 AM|mgebhard|LINK
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.
All-Star
52683 Points
15721 Posts
Re: How to access edited previous rows in sql database
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
Suwandi - Non Graduate Programmer