- What kinds of relationships can we represent in a database?
One to one, one to many/many to one, many to many and self-referencing.
- When do we use “One to One” relationships? Give an example from the real world.
Basic information requirement where there is a simple one to one, or exclusive, relationship (I.e. - each individual has a unique drivers license number or social insurance 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?
A separate table contains customer addresses. In this case, customer_id is also a field in the address table, as a foreign key, linking the customer information across two tables. Customer address could also exist as a field in the customer table.
-
Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
Sales: One purchase order can have many products. Many products appear on one purchase order.
- Give an example from the real world when would need to use a “Many to Many” relationship.
Sales: Many purchase orders can have the same product, which means a many specific product codes can appear on many purchase orders.
- What does items_orders table do?
The items_orders table is created specifically to tie the list of order numbers to their corresponding items, thereby creating the many to many relationship between items and orders.