From the course: Programming Foundations: Databases

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Many-to-many relationships

Many-to-many relationships

From the course: Programming Foundations: Databases

Start my 1-month free trial

Many-to-many relationships

- Another relationship used frequently in databases is called a many-to-many relationship. This model is useful when we want to associate more than one thing with more than one other thing. Let's consider orders and how we track them. Our orders table tracks individual orders from customers. There's only one customer per order and each customer could have more than one order, so that's a one-to-many relationship. But orders can be made up of more than one item. To keep track of which dishes are part of which order, we could start adding columns to the orders table and put a dish key in each one, but we shouldn't start adding columns here on the orders table because we don't know what the maximum number of items someone might order is. And if we make 50 columns, one for each potential dish a customer could order, most of our fields will remain blank. To solve this problem efficiently, we'll use a many-to-many relationship.…

Contents