Make a table for each "entity", such as "article" and "producer". Each such table would have an id
and a variety of attributes (name, etc).
Then characterize the "relationships" between pairs of those entities and build relations:
- 1:1
For one:one, rethink why you have two separate tables; consider merging the tables together.
- 1:many
For one:many, the "many" table needs a column with the
id
of the "one". And have anINDEX
on that column. - Many:many
For many:many, you need an extra table with only two columns, namely an id into each of the other tables. (Note: it is a waste to have a new
id
for this column. More discussion: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#many_to_many_mapping_table )
Then build relations:
For 1:1, rethink why you have two separate tables; consider merging the tables together.
For 1:many, the "many" table needs theA idFOREIGN KEY
of the "1".
For many:many, you need an extra table with onlydoes two columns, namely an id into each of the other tables. (Notethings: it isit provides a waste to haveconstraint that checks data integrity, and it makes sure there is a newsuitable idINDEX
for this column(for performance). More discussion: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#many_to_many_mapping_table (Foreign keys are desirable, but not required.)