2016-01-11 10 views
1

我有三個表格:service_type_1,service_type_2,service_type_3如何使用外鍵在一個表中存儲不同表的多值屬性?

這些表格有三個常見屬性:id,名稱,image_path

我想存儲一個以上的photo_path service_type_1表使image_path成爲一個多值屬性。 (這同樣適用於service_type_2,service_type_3表。)

所以,我創建了一個單獨的表稱爲photo_details存儲IMAGE_PATHservice_type_1通過表外鍵屬性ID連接它。現在的問題是我想用photo_details表來存儲IMAGE_PATH兩個service_type_2service_type_3也。

有沒有解決方案?

我應該爲service_type_2,service_type_3創建單獨的表嗎?

+0

不,請在'photo_details'表中添加列'type'。其中type = type_1,type_2,type_3 –

回答

0

添加列typephoto_details表,它應該看起來像:

photo_detail_id(PK)(int) type_id(FK)(int) type(enum) image_path(varchar) 
     1      1    type_1  path 
     2      2    type_2  path 
     3      3    type_3  path 
     4      1    type_1  path 
1

改變模型如果更多鈔票,以這樣的:

Table Types 
    Type_id int 
    Name varchar 

Table Details_photo 
    Id_detail int 
    Type_id int  Foreign key references Type_id in table Types 
    Name  varchar 
    Image_path varchar 

這樣你可以使用的種類數量不受限制值...

相關問題