2
I have a Relational Database structure. I will illustrate more briefly my tables:
Tab_client with fields (ID, Name, ETC...)
Tab_company with the fields (ID, Name, ETC...)
Image tag with fields (ID, Date, ETC...)
I would like to create a relationship 1.N from both Tab_client and Tab_company with Tab_imagem
As far as I know, I have to add a foreign key to the Tab_image, right?
However, I need to create a related FK for both Tab_client and Tab_company, right?
It would look something like:
Tab_image with the fields (ID, Data, ETC..., fk_client, fk_company)
Only that way, every line would have a primary key of the user you entered, but only one of them will do it and not both...
I thought about the possibility of creating something:
Tab_image with the fields (ID, Data, ETC..., fk_users)
This way I understand that each line of Tab_image will save only the primary key of the user who entered it, but I know how I would inform it to the bank, because as far as I know the code would be something like this:
FOREIGN KEY(fk_users) REFERENCES NOME_DA_TABELA (CHAVE_PRIMARIA)
A foreign key uniquely identifies a line of one another table, thus it cannot reference more than one table. Perhaps the use of partitioning can help you (https://dev.mysql.com/doc/refman/8.0/en/partitioning.html) but there is not enough data for a conclusion.
– anonimo
I get it, thank you.
– Eduardo Pereira