Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I have a question that I have thought for a long time. We have database tables, rows and data inside them.


Let's think about a simple table that keeps the items that in my pocket.

İtems_in_my_pocket
id item_name item_price
0 cellphone $150
1 money $70
2 einac(just kidding) $500,000


I want to update 2nd and 3rd row. I decide the row via id.

PseudeCode

Update the row that has id = 2 set item_pice to $0.
Update the row that has id = 3 set item_name to wallet and item_pice to $20.

How could I know the old values of these data? If I wanted to create a log panel, then it would
contain you updated einac(just kidding) to wallet
and so on..

What are the possible solutions? Does this belong to DBMS or SQL or the code itself(c#, java, php etc.)

Thanks.
Emre.
Posted
Comments
ZurdoDev 10-Oct-13 8:47am    
Create a table where you store history.
FoxRoot 10-Oct-13 8:47am    
How? Could you explain more ?
ZurdoDev 10-Oct-13 8:50am    
Create a table where you store the ID of the item and the price. You'll also need a timestamp and maybe even who made the change. It really depends on what you actually need.
FoxRoot 10-Oct-13 8:52am    
What will ı store in the new table? The old values?
ZurdoDev 10-Oct-13 8:53am    
Yes. The current table will always have the current value. The history table will store the previous values.

1 solution

Here is a article for logging the database changes.

Audit Trail – Tracing Data Changes in Database[^]
 
Share this answer
 
Comments
FoxRoot 10-Oct-13 9:00am    
I gave an eye to the article, that is what I am looking for. I wiil look deeper now. Thanks
ArunRajendra 10-Oct-13 23:18pm    
welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900