2016-11-14 74 views
-2
create table factura ( 
    importe money, 
    unidades_vendidas int, 
    subtotal as (unidades_vendidas * importe), 
    total as (subtotal * 1.18) -- (1.18 needs to be a constant value) 
) 

如何將「total」定義爲「小計」的1.18值?創建表格列「作爲常量值」

回答

2

就像錯誤消息說的那樣,您不能擁有基於另一個計算列的計算列。在你的情況下,解決方法是在第二個字段中重新計算。

create table factura ( 
    importe money, 
    unidades_vendidas int, 
    subtotal as (unidades_vendidas * importe), 
    total as (unidades_vendidas * importe * 1.18) 
) 

另外,您可以使用觸發器來填充你