Reading Assignment: SQL Relationships.
- What kinds of relationships can we represent in a database?
- One to One Relationships
- One to Many and Many to One Relationships
- Many to Many Relationships
- Self Referencing Relationships
-
When do we use “One to One” relationships? Give an example from the real world.
When we want to link a unique entity in one table with another unique entity in another table.
F.ex. instead of have the Address information in a Customer Table, we would only use Address ID that will refer the customer address entity in an Address Table.
Each address would only belong to one customer. -
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?
It will refer to the matching record in the Customer table.
We only need to call for these ID numbers in other tables. -
Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
F.ex. e-commerce store, where customer can take many orders that contain many items, where each item can have many different descriptions in many languages. -
Give an example from the real world when would need to use a “Many to Many” relationship.
When order can contain multiple items. And each item can also be in multiple orders. -
What does items_orders table do?
It creates relationship between Orders and Items.
Different Orders can include same Items.