-1

While reading Oracle 11g Sql by Joan Casteel, the author mentions that many to many relationships couldn't exist in relational databases. I was wondering what the reasoning behind this fact was.

1
  • 2
    That seems unlikely. Can you quote exactly what the author is saying? There are plenty of cases where you need a many-to-many bridge table because there are many to many relationships (i.e. a customer table, an order table, and a customer_order table to map customers to orders). Feb 15, 2022 at 3:00

1 Answer 1

2

I think it's a matter of terminology. As Justin mentioned, there can be many-to-many relationships in the real world. However, that requires an intermediary table in the database to bridge the gap at the relationship level. This intermediary table would be presented as a one-to-many relationship. When looked at from a higher level, the tables on the left and right of the intermediary table would represent a many-to-many relationship in the real world.

To elaborate on Justin's merchant example. A merchant can have many customers, just as they can have many products. Any number of customers can buy any number of products, just as any number or products may have been purchased by any number of customers. But you would never try to relate the two directly in the customer or product tables.

Instead, you would create an orders table. For each individual customer, you'd have a one-to-many relation for the number of orders they placed. While from the product side, you'd have a one-to-many relation from product to the number of orders.

If a relationship was not handled in this manner, picture a customer table needing to have a column for each product a user purchased, or a product table needing a column for each customer that purchased the product.

J.D. brought up a good point in the comments. Another way someone might make a mess of a many-to-many relationship would be...

a single generic column for the purchased product and a row for every product purchased per customer in the customer table. Such a denormalized design would result in the cardinality of the customer table not equaling the cardinality of the number of customers there are. Bridge tables for many-to-many relationships

So, to those points, the author is correct.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.