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 Quantit
If you update price or quantity you are forced to make a 2cd update on TotalPrice. What if another developer forgets the 2cd update? Now you have bad data.
You could have a trigger keep it in sync, but the possibility for bad data still exists. In some RDMS's the triggers do not fire for each row updated in a set-based update.
But sometimes it's needed to store calculated fields. If the table is BIG and you plan on searching the calculated field. (you must store the data to index it). In some designs you not only store the calculated fields, but aggregate calculations as well.
It's not always wrong to store calculated fields, just make sure you know the trade offs.
* EDIT * Another point. If you calculate "Amount_Paid", the actual amount the customer paid will be lost when you change the calculation formula.
Design to solve the problem. If that means breaking a rule of thumb, then break some thumbs. * END EDIT *