Re: The best way to insert tags in a DB

From: J.O. Aho <user_at_example.net>
Date: Sun, 20 Oct 2019 10:36:19 +0200
Message-ID: <h12kk3F1s0vU1_at_mid.individual.net>


On 19/10/2019 22.40, ^Bart wrote:
> Hi everybody! :)
>
> I need to insert in a db tags about food recipes and I thought to start
> in this way:
>
> recipes
> -------------------------
> id_recipe     name
> 1        hamburger
>
> recipetags
> -------------------------
> id_recipetag    name
> 1        meat
> 2        bread
> 3        latuce
>
> recipedetails
> ------------------------------------------------
> id_recipedetail    FK_id_recipe    FK_id_recipetag
> 1        1        1
> 2        1        2
> 3        1        3

As you don't have a one to one relationship, you should split out the FK_id_recipetag and have it's own relation table for it, it will be a lot easier to maintain the data.

I do still recommend you to use the same column name in all tables, this makes it easier to see which columns should be joined together and if you really want to use foreign key, then use a database engine which handles foreign keys.

-- 

  //Aho
Received on Sun Oct 20 2019 - 10:36:19 CEST

Original text of this message