- What kinds of relationships can we represent in a database?
There are several types of relationships that can be represented in a database. Some of the most common ones are:
- 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.
We use One to One relationships when a field can only have one relation with an attribute. For example, name of father; there is only one valid name related to each record.
- 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?
The customer_id functions as a primary key in the customers table; it’s the record that uniquely identifies each customer.
That unique reference is used as a foreign key in the customer address table to join the data of customer and address
- Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
- Many to One: a person that has several credit cards; all spending of each card will belong to the same person
- One to Many: orders on an e-shop, as one customer might have several orders
Give an example from the real world when would need to use a “Many to Many” relationship.
- Many to Many: several people can be signed for a course; this course might have several teachers giving the lecture and each teacher might give another courses as well.
- What does items_orders table do?
The items_orders table establishes the relation between the list of unique order id with its corresponding unique item id. The objective is to set a table with many to many relationship.