课程: Programming Foundations: Databases
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
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.…