-
What kinds of relationships can we represent in a database?
One to one, one to many, many to one, many to many, self referencing.
- When do we use “One to One” relationships? Give an example from the real world.
Data base of married couples. (Assuming we don’t have a many wives society). Data base of people’s birthday and place. Data base of people’s social security or tax reference or bank account. One person can only have one DOB or SS number.
- In the article in the “One to One”-section, the author of the article has a column called customer_id in the customers table. Why? How is it used in order to connect customers to addresses?
There is a table with links customer ids to their name and address. The id is then shorthand for that customer and is used to reference them in connection with orders.
- Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
Twitter: I as one user have many followers. I follow many people. One person can own multiple homes or properties hence one to many relationships. One gym can have hundreds of members, hence one to many.
- Give an example from the real world when would need to use a “Many to Many” relationship.
An open relationship? I have lots of partners and my boyfriend has lots of partners…sorry that example is rubbish, I should think of something better. Facebook friendships are many to many. I guess opinion polls would contain many to many relationships ie. People may each chose different options or answers to each question. However, instead of asking what person A thinks are the top three problems facing his country, you can also ask that question as, How many people said Covid was the number one problem facing the country? Hence many to many.
- What does items_orders table do?
Keep track of many to many relationships ie multiple orders can contain many of the same items as well as different items. Ie order #1 may contain items, A,B,C. Order #2 contains items C, D, E. So C has a relationship with two different orders, Order #1 and #2 have a relationship with three items each.
Keeps track
[/quote]
In