2013-07-20 49 views
0

我们可以将数组字段作为外键吗?例如,我有以下两个表:数据库 - 数组作为外键

Create Sequence Product_id_seq start with 1 increment by 1; 
Create Table Purchase (
Productid integer default next value for product_id_seq, 
Qty integer, 
cost decimal(17,2) 
); 

Create Sequence InvoiceNo_seq start with 1 increment by 1; 
Create Table Sales (
Invoice_Number integer default next value for InvoiceNo_Seq, 
qty integer, 
product_ids ARRAY, 
sale_value decimal(17,2) 
); 

我想在表的销售,如“Foreign Key (Product_ids) references Purchase (Productid)”添加约束。

为什么?

例如。我在7月1日购买了20台计算器,7月10日购买了10台计算器。我在7月13日售出了25台计算器,我应该能够指出这两台计算器的Productids,并将它们合并为25个编号(从productid 2的产品1和5生产20个)。这是阵列进入画面的地方。

我只是想确保数组包含值存在于Purchase.ProductId

可以达到?

回答

2

您可以使用触发器来实现这一点