Mysql, storing multiple value in single column from another table

前端 未结 3 477
攒了一身酷
攒了一身酷 2020-12-15 10:23


Bear with me, im really bad at explaining thing and i dont even know an appropriate title for this problem
Ok guys i have this problem
I already have one table

3条回答
  •  鱼传尺愫
    2020-12-15 11:06

    No. It's definitely not a good way to store data. You will be better with a combo_header table and a combo_details table.

    combo_header will be something like:

    +------+--------------+-----------+
    |  id  |  combo_name  | serving   |
    +------+--------------+-----------+
    |  1   |   combo1     |  2 person |
    +------+--------------+-----------+
    |  2   |   combo2     |  2 person |
    +------+--------------+-----------+
    |  4   |   combo3     |  2 person |
    +------+--------------+-----------+
    

    And then, combo_details will be something like:

    +------+-----------+
    |  id  |  meal_id  |
    +------+-----------+
    |  1   |  1        |
    +------+-----------+
    |  1   |  4        |
    +------+-----------+
    |  1   |  7        |
    +------+-----------+
    |  1   |  9        |
    +------+-----------+
    ... / you get the idea!
    

    By the way, by using multiple values in a single column you are violating first normal form of relational databases.

    The way I'm proposing will let you answer queries like get all name of the meals of combo1 very easy to resolve.

提交回复
热议问题