sqldatabase-design

Which is the parent and which the child in a SQL relationship?


What is the parent and what is the child in a sql relationship?

In my case, I have a part (Say screw), and product material. For argument's sake, a product material (eg steel) can only belong to one part (but not in the real world). So this is 1:n. The part will have its pk as a fk in the ProductMaterial table.

Which is parent and which is child in this case?


Solution

  • You can interpret a 1:n relationship in database this way: A child is always that model which holds the foreign key as this indicates where it belongs to.
    Of course if you have self referencing models/tables you have to look at it in a different way.