简单乘法的计算列? [英] Computed column for simple multiplication?

查看:245
本文介绍了简单乘法的计算列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作一个简单的库存应用程序。在表中,我有列数量,价格和TotalPrice。
更好,使TotalPrice a 计算列作为数量*价格或在我的应用程序中进行此计算,并将其保存在TotalPrice?

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?

推荐答案

数据库设计中的一个规则是(通常):不存储也可以轻松检索的信息。

One rule in database design is (in general): do not store information that can also be retrieved easily.

在您的情况下,我不会创建计算列,但在检索期间执行乘法。可以直接选择 price * quantity ,也可以创建一个包含此计算的视图。

In your case I would not create a computed column, but do the multiplication during retrieval. Either by directly selecting price * quantity or 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.

这篇关于简单乘法的计算列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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