【问题标题】:Guidance for database structure [closed]数据库结构指南[关闭]
【发布时间】:2015-06-22 03:04:20
【问题描述】:

我对这一切都很陌生。假设我想为世界各地的各种厨师制作一个网站(可能是大量数据)。在我的索引页面上,它会列出个人 "posts" 显示厨师和他们的 2 或 3 道特色菜。

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 值(菜肴的成分数量会有所不同)。 任何指导将不胜感激。

【问题讨论】:

    标签: php mysql database schema


    【解决方案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
    

    【讨论】:

    • 非常感谢@Mex
    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 2012-04-30
    • 2010-09-27
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多