2015-04-15 41 views
-1

我對這一切都很陌生。假設我想爲世界各地的廚師建立一個網站(可能是大量的數據收集)。在我的索引頁上,它會列出顯示廚師和其中2或3種特色菜餚的個人"posts"數據庫結構指南

chefstable [id, chef_name] 

dishtable [id, chef_id(foreign key), dish1, dish2, dish3(nullable)] 

在點擊該鏈接時,一個新的頁面將與更詳細的視圖加載,包括每個菜和個人成本每種成分以上+成分。

ingredientstable [id, dish_id(foreign key), ingredient1, ingredient2, ingredient3, ingredient4...(`nullable`), ingredient1cost, ingredient2cost, ingredient3cost...(nullable)] 

難道是比較可行的鞏固某些數據到一個表,或者他們確定分成不同的表,我會鏈接在一起。有沒有人有更好的方式有想法?

我很擔心這個結構,因爲會有很多null的值(菜餚會有不同數量的配料)。 任何指導將不勝感激。

回答

1

我會去與這種結構:

chefs 

id 
chef_name 

-- 

dishes 

id 
chef_id FK 
dish_type_id (1,2 or 3) 
value 

-- 

ingredients 

id 
dish_id FK 
ingredient_id (1,2,3 or 4) 
ingredient_cost 
value 
+0

非常感謝你@Mex –