Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are multiples foreign keys necessary?

I have Table A, this table has 3 foreign keys (id_tableA1, id_tableA2, id_tableA3).

I need a table that has a foreign key from Table A. I´m modeling in MySQL Workbench and the same program creates the structure below:

Table B

  • tableB_id (pk)
  • tableA_id (fk)
  • tableA1_id (fk)
  • tableA2_id (fk)
  • tableA3_id(fk)

Is this really necessary? Using tableA_id isn't enough? And then (if I decide to be necessary) retrieve data from tableA1, tableA2 and tableA3?

If you guys had the same question solved, please let me now the url for that. English is not my primary language and I had trouble searching.

like image 466
Max Avatar asked Dec 30 '25 20:12

Max


2 Answers

No, just have the fkey into tableA. If you need to pull in data using the further fkeys you can just join through tableA.

like image 83
chaos Avatar answered Jan 02 '26 09:01

chaos


no it is not required to have all those extra fk links.

it should be enough that the PK of tableA is tableA_id.

like image 21
Randy Avatar answered Jan 02 '26 10:01

Randy