2013-07-20 50 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

您可以使用觸發器來實現這一點