Answer the question
In order to leave comments, you need to log in
How to properly link two tables if the attribute of the first table is not always needed in the attribute of the second table?
The example is taken from the head, the real task is different, but similar.
Let's say there is a table of people and cars.
Люди
----
Id
Имя
Машины
----
Id
Марка
МашиныУЛюдей
----
CarId
PersonId
Answer the question
In order to leave comments, you need to log in
A car can belong to several people
M2M - many to many - intermediate table
The car belongs to only one and is somehow unique
O2O
- one to one - foreign key in the Car table or in the Person table
machines do not differ
O2M - one to many - FK in the table Man
Write table names in the singular
Both solutions do not affect performance in any way
Forbid yourself to think about performance until you have no load and the schema is in 3NF
Table "Person" (code, name), table "Machine" (code, number, brand), table "Brand" (code, name), table "Possession" (code, owner, car, exclusive).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question