Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep track of historical changes to reference table?
    primarykey
    data
    text
    <p>This is a very common thing in web applications. If I have a user table and I want to keep track of all the changes made to the user table, I can use a database insert and update triggers to save those changes in the user_history table.</p> <p>But what if I have user_products table, where I have user_id , product_id, cost. When I add a user in the system lets say I have two products associated with that user. So my user_products table will have two rows for that user. </p> <pre><code>user_id product_id cost 1 10 1000 2 20 2000 </code></pre> <p>Now if I go to the edit user page and delete product 1 , add product 3 , change cost for product 2 from 2000 to 3000. </p> <p>so normally I delete all records for user_id 1 from user_product table and then do a new insert for the new products. </p> <p>So its not a regular update but a delete and then insert. Hence I am not able to keep track of history changes. </p> <p>Ideally I would want to know that I deleted product 1 , added product 3 , changed cost for product 2 from 2000 to 3000. </p> <p><strong>EDIT 1:-</strong></p> <p>I am not doing a update. I am doing a delete and then insert. So I am deleting record with product id 2 and cost 2000. And then again inserting record with prod id 2 but with cost 3000. So technically its delete and insert but logically only cost is changed from 2000 to 3000. If i check while executing both queries it will say i deleted product with id 2 and and then added product with id 2 which are same. But I want to be able to see that the cost has chnaged from 2000 to 3000</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload