-
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 there cannot be more then one relationship between an entry.
Each fiscal ID for a single person and their main residence -
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?
That is the customer primary key. it identifies the person. this key can then be used in other tables, like table to reference the customer, like linking them to an order -
Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
A person and their orders, their houses if they own several. -
Give an example from the real world when would need to use a “Many to Many” relationship.
Many clients order from multiple vendor through a maket place and the vendor then has multiple clients -
What does items_orders table do?
it links the orders with the items they contain
- 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.
We use “One to One” relationships when each record in a table is associated with a single, unique record in another table. Example: A person’s passport number, where each passport is unique to one individual.
- 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
in the customers table uniquely identifies each customer. It is used to link each customer to their respective address in the Addresses table via a foreign key, creating the relationship between the two tables.
- Give an example from the real world when you would need to use a “Many to One/One to Many” relationship.
Example: In a school database, one teacher can teach many students (One to Many), but each student is assigned to one teacher (Many to One).
- Give an example from the real world when you would need to use a “Many to Many” relationship.
Example: In a university setting, students enroll in multiple courses, and each course has multiple students enrolled. This relationship is managed through an enrollment table linking students and courses.
- What does the items_orders table do?
The items_orders
table establishes a “Many to Many” relationship between items and orders by linking item IDs to order IDs, allowing each item to appear in multiple orders and each order to contain multiple items.
- 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.
We use “One to One” relationships when each record in a table is associated with a single, unique record in another table. Example: A person’s passport number, where each passport is unique to one individual.
- 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
in the customers table uniquely identifies each customer. It is used to link each customer to their respective address in the Addresses table via a foreign key, creating the relationship between the two tables.
- Give an example from the real world when you would need to use a “Many to One/One to Many” relationship.
Example: In a school database, one teacher can teach many students (One to Many), but each student is assigned to one teacher (Many to One).
- Give an example from the real world when you would need to use a “Many to Many” relationship.
Example: In a university setting, students enroll in multiple courses, and each course has multiple students enrolled. This relationship is managed through an enrollment table linking students and courses.
- What does the items_orders table do?
The items_orders
table establishes a “Many to Many” relationship between items and orders by linking item IDs to order IDs, allowing each item to appear in multiple orders and each order to contain multiple items.
-
What kinds of relationships can we represent in a database?
We can represent one-to-one, one-to-many (many-to-one), many-to-many, and 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 one entity can only be associated with one other entity. For example, one address can belong to one user.
-
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 to connect customers to addresses?
The customer_id in the customers table uniquely identifies each customer and is used to link to the corresponding address in the addresses table.
-
Give an example from the real world when we would need to use a “Many to One/One to Many” relationship.
An example would be the relationship between customers and orders, where one customer can have multiple orders.
-
Give an example from the real world when we would need to use a “Many to Many” relationship.
An example is the relationship between items and orders, where an order can contain multiple items, and an item can be included in multiple orders.
-
What does the items_orders table do?
The items_orders table establishes the many-to-many relationship between the orders and items tables by linking order_id and item_id.