- What kinds of relationships can we represent in a database?
- one to one rel.
- one to many and many to one rel.
- many to many rel.
- self referencin rel.
-
When do we use “One to One” relationships? Give an example from the real world.
when there can be only an attribute can only be matched to exactly one other attribute.
lets say in table 1 you have the e-mail Address and password of a user. and in table 2 you have the usernames. each username can only be link to one email and to one password. each email can only be related to one username. -
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?
Each customer id gets one adress Id. this foreign key is then used to find the address. To do so you would enter the customer id, from that you derive the address Id and from there you get the address from the address table. -
Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
When the children are related to a father. there can by two children, none, or one child be related to one father. Probably you would use a many to many because the children are also related to a mother.
another example could be picture to profile pictures on FB. Because you can have many profile pictures. -
Give an example from the real world when would need to use a “Many to Many” relationship.
children to parents. each child has two parents, and each parent can have 0, 1, 2, etc. children -
What does items_orders table do?
It links items to the orders