2016-11-14 78 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) 
) 

另外,您可以使用触发器来填充你