Question

Suppose I have the following relationship diagram:

Diagram

How would you describe the relationship determined by the red line?

Reading from left to right you would say each order has only one customer so it could be described as a "many to one" whereas from right to left each customer can have many orders so you could say it is "one to many".

Without direction it seems to me to be futile to try and discuss a relationship yet I rarely see people say, it is a one to many (from customer to order) or many to one (from order to customer).

So my question is why is this the case (is it just implied from context?) or does the primary key have some relation, as in we wouldn't really store an order_ID in the customer table (I am not a DBA but I don't think this make sense from a design point of view) whereas we would have to store a customer as a foreign key in the order table otherwise we wouldn't know who bought the stuff, so would this give precedence to reading from right to left and we say the red line is a one to many relationship?

Any clarification would be great!

Était-ce utile?

La solution

A Foreign Key always refers to a Unique Index or Primary Key. So the "one" side is always the one where the related columns are a key.

Autres conseils

In most cases the way you describe entities and their relationships in your model simply follows the natural order of things IRL. Orders don't suddenly appear by themselves and spring customer references. Customers come first, and each of them can have zero or more orders, to which they grant references. Going to the physical model, again, you must have a customer row before an order row for the referential integrity constraint to work.

Licencié sous: CC-BY-SA avec attribution
Non affilié à dba.stackexchange
scroll top