食品订购系统 - 数据库设计

时间:2014-05-19 21:15:09

标签: mysql database-design mysqli

我正在为我的数据库中的每个餐馆创建一个表格,以便我可以在提供个人资料时动态调用它们。

问题: 餐厅菜单卡存在巨大差异,因此无法标准化数据。

当前Sol-n: *我已经构建了如下所示的数据

http://i.stack.imgur.com/AbqON.png

^这些是两个不同餐厅的结构,因为您可以识别它们的菜单卡各不相同。

每个菜单类别都有5列,以便更好地进行分类。管理这种数据库非常忙碌,非技术人员也很难进行数据输入。

我做错了吗?请纠正我,一些代码参考会很明显。

2 个答案:

答案 0 :(得分:1)

我宁愿使用两张桌子。

首先为产品创建一个表:

product_id,text,cat,desc,price

然后为订单创建一个表

order_id,product_id,sequence,type

所以你可以在一个订单中只提供两种产品,例如:

order_id 1, product_id  5, sequence 1, type starter
order_id 1, product_id 20, sequence 2, type main
order_id 2, product_id  4, sequence 1, type starter
order_id 2, product_id  6, sequence 2, type starter
order_id 2, product_id 22, sequence 3, type main
order_id 3, product_id  4, sequence 1, type starter
order_id 3, product_id  6, sequence 1, type starter
order_id 3, product_id 22, sequence 2, type main    
order_id 3, product_id  4, sequence 2, type starter

序列显示何时为菜提供服务,类型并不是真正的nessesary,但我继续你的例子。下一步是检查同一桌上2个人订购同一产品的情况?要么使用数量 - 但我希望在订单表中两次使用相同的产品。 - 因此,当有人为主要课程订购入门时,您可以自由更改顺序(请参阅order_id 3)。

答案 1 :(得分:1)

对于那些将来阅读的人,以下是我对上述设计的看法:我个人不喜欢它。 OP可能会遇到麻烦。

  1. 将所有内容分解为单独的表格。

    • 打破了首发和主表。
    • 有一个名为'餐馆的单独表格。
    • 使用连接表
    • 例如使用客户表来链接所有内容。
    • 表的名称应为复数。
  2. e.g。

    starters
    starter_id
    starter_cat etc.
    

    电源 main_id main_cat等。

    Restaurants
    restaurant_id (primary key)
    restaurant_name
    .... etc etc. further information
    

    现在有一个联接表,告诉您餐馆可以订购哪些商品: restaurant_menus restaurant_id

    Customers
    customer_id
    customer_name
    

    现在使用连接表将客户与他订购的产品联系起来:

    Customer_orders
    customer_id
    then you have your order item id here: [starter_id]/[main_id] etc
    

    同样使用连接表将特定餐厅与该餐厅提供的菜单项链接起来。很可能两家餐馆的菜单上至少有相同的商品。

    我会把它作为练习留给你。