Reputation: 3418
Why do we define the minimum and maximum cardinality? What is it used for? Readability? How does it relate to the concept underneath? If I understand correctly, a relationship between entity's is nothing more than a SQL join.
Upvotes: 0
Views: 3582
Reputation: 52137
Nope, relationship is not a JOIN, although JOINs are often (but not always) done on top of relationships.
Cardinality is fundamental property of relationships between different pieces of data you are trying to represent in your database. For example, let's consider a "books and authors" database...
The important point is that these relationships need to be enforced no matter how you query or attempt to modify the data. Letting the DBMS enforce them for you by through declarative referential integrity (i.e. foreign keys) is usually the best way of doing it.
When you have an Lmin..Lmax : Rmin..Rmax relationship1, it means that:
When Lmax = 1, omitting Lmin means the lower bound is 0 or 1 (ditto for Rmax/Rmin). Confusingly, saying 1:N can mean either 0..1:N or 1..1:N.
When Lmax = N, omitting Lmin typically implies 0 (ditto for Rmax/Rmin). Non-zero lower bounds are extremely rarely used on the "many" side of relationships.
Replacing Lx and Rx with "0", "1" and "N" will give you various possible combinations, the most common and important of which are:
The term "cardinality" has another (and quite distinct) meaning, which is related to the number of rows returned from a (sub)query. Unless clear from the context, always clarify which of the two you are using...
Also, there is a difference between relationSHIP and relatiON. "Relational" databases happen to derive their name from the latter.
1 Pronounced "Lmin or Lmax to Rmin or Rmax".
Upvotes: 4