Best way to maintain a customer's account balance

前端 未结 8 620
孤独总比滥情好
孤独总比滥情好 2021-02-06 10:24

Is it better to have a field in the database that stores the customers account balance or use views and queries to generate the information.

8条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 11:10

    Everyone here's right. It does depend. But you can have the best of both worlds by using a view. Sounds like you might have a fairly small system, and dynamically calculating the balance will be the easiest thing to do. In order to keep it simple, I would define a single view that has the account data you want (calculated dynamically).

    If you're going to need more performance than that, I would set up a trigger-based system for updating the balance to the main account table, then update the view behind the scenes so you don't need to change any other code. Just make sure you're using the right database isolation mode for either query, or you'll be in trouble! ;-)

提交回复
热议问题