数据库中的派生值 [英] Derived value in database

查看:71
本文介绍了数据库中的派生值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,我正在使用sql server 2008在ASP.net4中开发一个中型购物中心的应用程序.我应该在数据库中存储诸如总价"之类的派生值,还是应该在必要时每次根据单价计算此类值.早些时候,我更喜欢将这种类型的派生值存储在数据库中,因为它帮助我非常轻松地向用户显示数据.等待您的建议.谢谢朋友.

解决方案


将计算的(汇总)数据存储在数据库中不是一个好习惯,为了简化报表,设计视图并将其绑定到报表中!
根据您当前的逻辑,想象一下这里的不同情况,如果客户取消了订单或更改了特定订单中的项目数,则需要再次进行计算,并且需要更新汇总字段!但是如果您不将它们保留在数据库中,那么您就不会在乎,因为您认为视图会处理这些计算,并且您的客户会获得正确的结果.


Friends, I am developing an application for medium size shopping mall in ASP.net4 with sql server 2008. Should I store derived values like Total price in database or should I calculate this type of values from unit price each time when necessary. Earlier I preferred storing this type derived values in database as it helped me to show data to the user very easily. Waiting for your suggestion. Thank you friends.

解决方案

Hi,
It''s not a good practice to store calculated (aggregated) data in the database, for your report''s simplicity, design a view and bind it to your report!
Imagine different scenarios here, based on your current logic, if the customer canceled the order or changed the number of the items in specific order, you need to do the calculations again and you need to update your aggregated fields! but if you aren''t keeping them in the database, you don''t care because you''re view will take care of the calculations and your customer will get the correct results.


这篇关于数据库中的派生值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆