0

I am working on a project for a Market (Mini Market). And I want to create a Storage Table where I have all my products. And in this table there is a QUANTITY Column and the PURCHASE PRICE Column. And I want to add the TOTAL column. In the total column it should show me the price of:

TOTAL = QUANTITY * PURCHASE PRICE

And I wanted to ask you about how should I do this (TOTAL = QUANTITY * PURCHASE PRICE)? I there any option to do this while I am creating the Table in SQL SERVER? Or I have to do this in the C# code?

Please help me guys?

4

2 回答 2

4

理论上,你根本不应该这样做——在关系数据库中,派生字段不应该存储在数据库中,而是根据需要派生。

于 2012-12-13T19:22:51.467 回答
1
 Update MyTableName Set
    Total = Quantity * PurchasePrice

但是您应该考虑在需要它的选择查询中即时计算它,或者添加一个计算列。

Alter Table MyTableName  
Add Column Total = Quantity * PurchasePrice
于 2012-12-13T19:24:56.517 回答