I making a simple inventory application. In a table i have columns Quantity, Price and TotalPrice.
Which is better, make TotalPrice a Computed Column as Quantity*Price or do this calculation in my application and save it in TotalPrice?
I making a simple inventory application. In a table i have columns Quantity, Price
Share
One rule in database design is (in general): do not store information that can also be retrieved easily.
In your case I would not create a computed column, but do the multiplication during retrieval. Either by directly selecting
price * quantityor by creating a view that contains this computation.The view has the added benefit, that you can easily change the formula (e.g. including VAT) without the need to change all statements in your application.