Values that are calculated, if you store the value with the calculations in the database?

Asked

Viewed 193 times

0

I am developing a system where a product undergoes 3 changes before reaching its final value:
Individual Discount, Selling Bonus and General Discount
I want to know if, I should store only the original value of the product in the database or if I already do all calculations related to that product and then save the final value of it.
In my case, daily calculations would still be done. It would work as if it were quantity. Product * daily.
By database normalization, as would be the correct procedure to persist this data?

  • 2

    It is information, store separately.

1 answer

1

You choose, if your system is architected to have a database processing, then you can already store the final value of the product, but this will prevent you from knowing what were the discounts right at first (You would have to undo the calculations for this).

If you run the calculation before storing the value and in the end already store it discounted, you would need to create a field in the table to store the original value. Whereas if you store the original value you can display the discount value in a view, but the process can be the reverse too.

Anyway, it depends on your architecture, what do you feel most comfortable? Store the original value and then discount? Or the other way around?

  • Then my question becomes another. In case of storing the original value and the appropriate discounts in the database, every time I need to present the value of this product, I will need to make the calculations in my application?

  • So, depending on what you’re using, I would advise using views, they would take the actual product values and add in new columns where the final value would be calculated.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.