我一直收到这个错误:
在此上下文中不允许使用子查询。只有标量表达式 允许
代码:
Create table SaleFact
(
CustomerKey int not null,
EmployeeKey int not null,
ProductKey int not null,
ShipperKey int not null,
TimeKey int not null,
LineItemQuantity int null constraint "DF_SaleFact_LineItemQuantity" Default(1),
LineItemDiscount money null constraint "DF_SaleFact_LineItemDiscount" Default(0),
LineItemFreight money null,
LineItemTotal money null,
Constraint "PK_SaleFact" Primary key Clustered
(CustomerKey,EmployeeKey,ProductKey,TimeKey),
Constraint "Fk_CustomerKey" Foreign Key
(
"CustomerKey"
)
References "dbo"."CustomerDimension"(
"CustomerKey"),
Constraint "Fk_EmployeeKey" Foreign key
(
"EmployeeKey")
References "dbo"."EmployeeDimension"(
"EmployeeKey"),
Constraint "Fk_ProductKey" Foreign key
(
"ProductKey")
References "dbo"."ProductKey"(
"ProductKey"),
Constraint "Fk_ShipperKey" Foreign key
(
"ShipperKey")References"dbo"."ShipperKey"(
"ShipperKey"),
Constraint "Fk_TimeKey" Foreign key
(
"TimeKey")References "dbo"."TimeKey"(
"TimeKey"),
Constraint "ck_LineItemQuantity" check(LineItemQuantity>=0),
Constraint "ck_LineItemDiscount" check(LineItemDiscount>=0 and LineItemDiscount<=1),
Constraint "ck_LineItemFreight" check(LineItemFreight>=0),
Constraint "ck_LineItemTotal" check(LineItemTotal =LineItemQuantity* (select ListUnitPrice from ProductDimension )) //this lineitemtotal is the one where I kept getting an error saying that subqueries are not allowed in this context. Because I'm trying to that listunitprice from the table name ProductDimension
)