Skip to main content

Appendix A — Calculated Attributes

The dilemma

When designing a database, you come across attributes whose value you can calculate from other fields. Think of:

The question is whether you should store these calculated values in the database or not. There is no simple answer. It depends on the type of data and on the situation.

According to strict normalization rules, you should not store calculated fields in a database, since you can always have the value calculated when you need it.

But practice is different

In practice, there can be good reasons to store calculated values after all. What are the problems?

  1. Historical prices (the most important reason!)
    Suppose a laptop costs $799 today, and a customer orders and pays for 1 laptop. If the price is raised to $899 a month later, there is a problem when Subtotal is not stored in the database but calculated. For the laptop bought a month earlier, the calculated amount is then Quantity * Price = 1 * 899 = 899. And that is wrong, because the customer paid only $799.

  2. Discounts and special offers
    Suppose a product normally costs $50, but the customer gets a 20% discount.

When to store and when NOT to store

Do NOT store when:

DO store when:

TipRules of thumb for your design

DO store calculated values when:

  • ✅ It involves money (prices, amounts, discounts)
  • ✅ It is a transaction or event (order, payment, booking)
  • ✅ The underlying values can change (prices, rates)
  • ✅ You want to keep a “snapshot of that moment”

Do NOT store calculated values when:

  • ❌ The value changes continuously (age, inventory)
  • ❌ It can always be calculated from current data
  • ❌ There is no financial or historical component
  • ❌ The underlying data is permanent