Home > Software engineering >  What is the relationship between customer and order?
What is the relationship between customer and order?

Time:01-26

I'm confused what is the relationship bewteen customer and a order. Most of websites says its One to many because One customer can place many order. If we see physically its many to many because there is customer and there is product. In SQL table if I see the relatiosip tabe

Customer

Cid Cname
1001 A
1002 B
1003 c
1005 D

Product

Pid Pname
P1 Soap
p2 Dettol
p3 Toothpaste
p4 sanitizer

Relationship table (many customers can orders many product)many to many orders

cid pid Pname
1001 p1 Soap
1001 p3 Toothpaste
1002 p1 Soap
1003 p3 Toothpaste
1005 p4 sanitizer
1005 p1 Soap

How you do consider this one to many? Many coustomers can order many product's if we see real life. if you know the answer just prove it one to many.

Many to many Relation i am expecting

CodePudding user response:

Customer and Order should be one to many, not many to many. Imagine this, a customer can make many orders, but can an order by ordered by more than one customer?
If you're talking about products, it's a different entity called Product which only contains information about a product. Products and Orders relationship is many to many since one order can have many products and the reverse is also true. In summary, Customer and Order is a one-to-many, Product and Order is a many-to-many. Hope it makes senses.

CodePudding user response:

One-to-many means that for each one customer there can be many orders. It doesn't mean that there's only one customer in the entire table.

Many-to-many means that you have a one-to-many relationship in both directions: Each customer can have many orders, and each order can have many customers. That's not normally allowed in an order database, each customer gets a different order.

The relationship between orders and products will be many-to-many, since many customers can order the same product. But each has to go through a different order.

CodePudding user response:

this concept can best be understood by referring to yourself (One) as a customer who is making a purchase. it is normal that you can purchase so many things by yourself from more than one sources, which makes it one to many, and the same product or item which you purchased, is literally more than one in that same source you got yours, can also be distributed to many people, which makes it many to many

  • Related