From what I understand, 1)table customer and table order should have a one to many relationship since customer has orders. 2)table order and table payment should have a one to many relationship since a single order can have multiple payments. 3)table order and table delivery should have a many to one relationship. Is this correct? Am I missing something else?
1 Answer
The design depends on your business requirements, but in general that sounds like a good design and valid for the context.
Some very minor things you can consider are the following:
In real life different
Customers
can technically live at the same Address, and therefore if you normalizedCustomerAddresses
to their own Table, it would reduce redundancy and theoretically can improve performance.Some real life scenarios allow a
Customer
to use multiplePayment
methods for the sameOrder
. If this will never be a use case in your system then you can ignore this. But if it's possible you want to support that feature, then you'd need to update the relationship betweenOrder
andPayment
so that it was one-to-many.You may want to consider to split the
Order
table into two tablesOrderHeader
andOrderLine
. Then there would be a one-to-many relationship between the two tables, since multiple lines can go on the same header. The header would store the general Order information like OrderId, OrderDate, OrderTime, CustomerId but the OrderLine table would have a separate line for each type of item ordered, and it would store the PizzaId and Quantity (and any other specific information, such as customizations to the item ordered).As it stands right now with your current design, your
Customer
can only order one type of Pizza perOrder
. By splittingOrder
into two tables like above, they'd be able to order multiple different kinds of Pizza on the sameOrder
(or even other types of items that may be sold later on, like cheesy bread and soda).
-
1
-
No problem, if you have any further questions, feel free to ask, and I'll do my best to answer!– J.D.Commented Dec 23, 2020 at 14:06
-
I've updated my post picture. I tried to do what you suggested. Is this correct? Commented Dec 23, 2020 at 14:17
-
@KhishigdelgerGanbold Almost. You need to add the
OrderId
to theOrderLine
table as a foreign key so it can reference it's respectiveOrderHeader
. It also should have it's own primary key, likely called something likeOrderLineId
or justLineId
if you prefer.– J.D.Commented Dec 23, 2020 at 14:23
OrderID
.