r/DatabaseHelp • • Apr 28 '17

Need help with database structure

I have a restaurant that has 24 items on the menu. I need to create an orders table that keeps track of items in an order and then send the order to the kitchen. Do I create a table like this.

orders
    order_id    item1    item2    ...    item24
    -----------------------------------------------------
    1              1           0                 1

And keep a counter of item in each column? Or should I create another table for every single order and each row is an item with a quantity, like this

order1
    item_name    quantity
    ----------------------------------------------------
    item1            1
    item2            0
    item24          1

If it's the latter, there would hundreds or thousands of these tables, wouldn't it?

2 Upvotes

7 comments sorted by

View all comments

Show parent comment

2

u/NotImplemented Apr 29 '17

Then, would it better if I have an order_details table that stores data like this?

Yes. That way the number of ordered items is not fixed and can differ between orders. Otherwise, orders could maximally have 24 different items (one for each item column) and if an order has less items you would get lots of NULL values.