Multiple foreign keys within a field of another table?

0

Good morning, I am developing an Android application where I have this database.

-Tables Food:

  • ID Primary Key char (15)
  • Name char (25)
  • Description char (35)
  • Tags char (35)

-Tables Tags:

  • ID Primary Key char (15)
  • Name char (15)

An explanation of everything, in my database the primary key of the labels table will be connected through a foreign key to the label field in the meals table. Is it possible that I can bring multiple foreign keys within this field ?, And if so, how do I do it? Because I want the app to have several tags so that you can search for the foods through these, yes no Is there any way to optimize the database? .

    
asked by Manuel Real 06.06.2018 в 23:49
source

1 answer

-2

No. First, the keys should be numeric. Then, if they were varchar, they should be exactly the same.

And for what you want, I recommend that you read about database theory, but you need an intermediate table, since you have an NXM relationship, which means that you will have many records in a table related to many records in another table.

Therefore, you should have 1 intermediate table like this:

Tabla EtiquetasComida:
IdEtiquetaComida
IdEtiqueta
IdComida
    
answered by 07.06.2018 в 00:01