SQL Relationships - Reading Assignment

  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. use 1 - 1 relationships for assigning one record to another one record in a table.
    use case : collecting an email list / social security / ID / cell number

  2. customer_id is an example of a 'Foreign Key" and used to create a referential relationship between an attribute and a record.

  3. many to one , vice versa example: Instagram followers / youtube subscribers

  4. social media explore pages - many users connected to many pages and so on
    food delivery service - many drivers and many customers

  5. to create a “Many to Many” relationship between the items and the orders

2 Likes
  1. 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
  1. When do we use “One to One” relationships? Give an example from the real world.
    For assigning one value to one other value. One customer has one address.

  2. 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 is the primary key which can relate to their address_id a foreign key.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    When one customer makes more than one order.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    When one order can include many different items/products.

  5. What does items_orders table do?
    It shows the relationship between items and orders.

3 Likes
  1. What kinds of relationships can we represent in a database?
    one to one, one to many, many to many, self referencing relationships
  2. When do we use “One to One” relationships? Give an example from the real world.
    one to one relationships are used when one row in a table only has a relationship with one row in another table. An example is a customer and their username
  3. 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 column gives the customer a foreign key where the relationship between the customer and the address can be clearly defined.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    many to one relationship would be student and math teacher where there are 5 teachers and 100 students
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    a many to many relationship would be a table that shows the student, their teacher and their class subject
  6. What does items_orders table do?
    it creates a many to many relationship between the items and the orders
2 Likes

1.What kinds of relationships can we represent in a database?
one to one relationship
one to many and many to one
many to many
self referencing.

2.When do we use “One to One” relationships? Give an example from the real world.
one individual and his address. one on one relationship is used when there is only one relationship in an entry

3.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’s a foreign key for matching records in the address table, it identifies the right records that belongs to a specific customer.

4.Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
when a person has got more than one phone contacts and also e-commerce a person makes an order for many different items.

  1. Give an example from the real world when would need to use a “Many to Many” relationship.
    At a school when you want to find out the relationship between the students and their parents

6.What does items_orders table do?
it relates between the items and the order table hence makes a respective identification of many to many relationships.

1 Like
  1. 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
  1. When do we use “One to One” relationships? Give an example from the real world.
    A person and their state ID number.
  2. 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 is the primary key which relates to their address_id a foreign key.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Any e-commerce platform: a client can have multiple orders, orders can contain the same item.
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    Again, any online shop or e-commerce business.
  5. What does items_orders table do?
    Creates the relation between items and orders.
1 Like
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. When you want to arrange information, in a table, that can only be linked to another piece of information. For example, in a table for customers, you can have their addresses next to the name of the customer.

  2. This is the Foreign Key and they are used to connect databases in a variety of ways. It is used to ensure the data’s referential integrity.

  3. Using the example of people, we all have one surname, however, we may have more than one relative, outside our immediate family.

  4. Imagine you’re setting up an online dating profile… One person may have a lot of interests that they add to their profile, and from this, the dating app/site will produce a lot of potential matches based on your interests.

  5. The main function of the items_orders table is to construct a “Many to Many” relationship between the items and the orders.

1 Like

My Answers:

  • One to one
  • One to many and many to one (Most commonly used)
  • Many to many
  • Self referencing
  1. Where an entry in one table is associated with one and only one entry in another table. An example is a Passport ID assigned to only one person.

  2. In this case each customer_id has an order_id and that shared column/field characteristic creates a ‘Foreign Key’ to match the entry of the Address table.

  3. Many people live in one city / A city contains many people living within that area.

  4. Many customers can purchase many products / Many products can be purchased by many customers.

  5. It is there to create a ‘many to many’ relationship between the items and the orders.

1 Like
  1. One to One Relationships
    One to Many Relationships
    Many to Many Relationships
    Self Referencing Relationships

  2. In a one to one relationship, one record in a table is associated with one and only one record in another table. An example would be in a school database, each student has only one student ID and each student ID is associated to only one person.

  3. This is called Foreign key and it is a column or group of columns in a relational database table that provides a link between data in two tables.

  4. Many to One relationships is most commonly used. Consider an e-commerce website where customers can make many orders, orders can contain many items and the items can have descriptions in many languages.

  5. An example of a Many to Many relationship is one between students and classes. A student can register for many classes, and a class can include many students.

  6. The items_orders table creates the “Many to Many” relationship between the items and the orders.

1 Like
  1. 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
  1. When do we use “One to One” relationships? Give an example from the real world.
    When the entry into the database can only belong to one user. For example: my email address belonging to my Ivan on Tech user ID.

  2. 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?
    This is the only ID that the customer has and is connected to the only address that they filled in.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    For a company that gives incentives to people who recruit new customers to the company they can get a kick back. Their referral code can be used multiple times in sign ups.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    The Amazon order system has many items that can be ordered from multiple people and the same person can put in multiple orders.

  5. What does items_orders table do?
    It matches the order_id to the item_id, therefore creating a many to many relationship.

1 Like
  1. Relationships can be one-to-one, one-to-many/many-to-one, many-to-many, and self referencing relationship
  2. We use one to one relationship when only one item corresponds to another item in another table in a database. e.g., The address of a customer can belong only to one customer.
  3. There is a customer_id in the customers table because this references the whole row of a customer record. If then later on we want to input/refer to that customer, we simply input the id eliminating redundancy of data entry.
  4. A real world example of a “Many to One/One to Many” relationship would be one dog owner, many pet dogs belonging to him.
  5. A real world example of a “Many to Many” relationship would be a list of siblings. Many siblings would be in a “sibling” relationship with his/her other siblings.
  6. “items_orders” stores data of orders from various customers.
  1. there are “one to one”, “one to many”, “many to one”, and “many to many”.

  2. We use “one to one” relationships when we want to pair a single element with another single element. An example would be pairing customer names to their affiliated addresses.

  3. Instead of looking up a customer by their name, the customer id is 3 digits and would streamline any searches involved since it is more consistent in length unlike customer names.

  4. a “one to many” or “many to one” relationship is often used to search up for multiple elements from one entry. An example would be looking up a customer ID and retrieving all the orders that customer has made in the past, including the date of their order, amount paid, and etc.

  5. A “many to many” relationship can be used when both sides of the relationship has multiple elements. An order ID that contains specific data about the order relating to an item purchased that includes the product name, description, colour, etc.

  6. “ITEMS_ORDERS” states the relationship between the “ORDERS” table and the “ITEMS” table by linking the order ID to the item ID.

1. What kinds of relationships can we represent in a database?

There are many kinds, some of them are

  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships

2. When do we use “One to One” relationships? Give an example from the real world.

This kind of relationship is not very common, but an example can be the ID each citizen has. Because each citizen has its own ID and each ID correspond to only one citizen.

3. 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 is used as a foreign key in the adresses table to make the relation between the customer and the adress wich is stored in another table.

4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.

An example can be all my utensils inside my pencil-box. I have many different utensils which they only belong to me (One-to-Many). All those utensils have one owner which is me (Many-to-One). @thecil is that correct?

5. Give an example from the real world when would need to use a “Many to Many” relationship.

Many-to-Many examples are when the object/item/product/etc. can be shared. In the morning breakfast I can eat cereal and have coffee, my brother can drink orange juice and my father can also have coffee.

6. What does items_orders table do?

The items_orders is specifically make as a “Many to Many” relationship between the items and the orders.

1 Like
  1. 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 relationships.

  1. When do we use “One to One” relationships? Give an example from the real world?

A One-to-One relationship is present when one value in table A corresponds to exactly one value in table B. As an example, only one passport ID number corresponds to a particular person and vice versa.

  1. Why does the author use the column called customer_id in the customers table?

In this case, customer_id is used as a foreign key in the customers table. This foreign key can be used to retrieve relationships between a particular data item’s elements across different tables, in this case across the customers table and orders table.

  1. Give an example from the real world when you would need to use a “Many to One/One to Many” relationship.

Many-to-One relationship: Many people can work for the same company.

One-to-Many relationship: One type of mobility can be utilized by different people (e.g. many people use the car for mobility).

  1. Give an example from the real world when you would need to use a “Many to Many” relationship.

When you have portfolios and their assets. Each portfolio can contain many asset types, and each asset type may be included in many portfolios.

  1. What does the items_orders table do?

In this example, it is used to illustrate a Many-to-Many relationship between orders and items.

1 Like
  1. There are several kinds of relationships which can be represented in a database:
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. “One to One” relationships are used in databases where there is a relationship between aspects of a single user across two or more tables. An example of One to One relationships used on a shopping website (provided each address can belong to only one customer) is to show the relationship between the customer’s name and their address.
  2. In the article in the “One to One” section, the author of the article has a column called ‘customer_id’ in the customers table because it creates a further search term for the database, i.e. allows for faster retrieval of customer data. In order to connect customers to addresses it is used via One to One relationships: customer_id to address_id.
  3. An example from the real world when you would need to use a “Many to One/One to Many” relationship would be on a shopping website to link customers to their orders across tables of the database.
  4. An example from the real world when you would need to use a “Many to Many” relationship would once again be on a shopping website to link customers to orders containing multiple items, and where each item can also be in multiple orders.
  5. The ‘items_orders’ table has one purpose only, and that is to create a “Many to Many” relationship between the items and the orders on a shopping website.
2 Likes
  1. 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
  1. When do we use “One to One” relationships? Give an example from the real world.
    –> When do we shall have only one correspondent value (e.g. My name and my ID card number, another person might have the same name as me, but it can’t be associated to the same ID card number).
  2. 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?
    –> To uniquely identify a customer in this table.
    –> There is a table called ADDRESSES, where is stored the adress of each customer which is linked to the CUSTOMERS table by the column address_id.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    –> A student (in a table STUDENT) would have several assignments associated to him/her. Assignments would be in a table ASSIGNMENTS.
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    –> A Bill of Material (BOM) could have many part numbers from a table called PART_NUMBERS. The same part number might be included in different Bill of Materials.
  5. What does items_orders table do?
    –> It has only one purpose, and that is to create a “Many to Many” relationship between the items and the orders.
2 Likes
  1. We can represent One to One, Many to One, One to Many, Many to Many and Self referencing relationships.

  2. For example when we want to define the relationship between Name and Social security number. One name only corresponds to one unique social security number.

  3. That is a primary key or a foreign key in the Orders table. That key can be used for the relationship between the two tables, Customers and Orders.

  4. Many to One could be that many orders correspond to one customer. One to many could be that one item can be in many orders.

  5. Many items can be in many orders for example.

  6. It provides the relationship between many order id and many item id.

2 Likes
  1. One to one, one to many and many to one, many to many, self referencing
  2. For a school: list of students who have all a unique student number
  3. The customer_id refers to another table where every customer is store with a unique customer identification
  4. Zalando: every customer has a unique id but can make several orders with different orders id
  5. School programm: a student can register for multiple classes, whereas a class can include multiple students.
  6. It is there to create the many to many relationships between items and orders
2 Likes
  1. What kinds of relationships can we represent in a database?
    A. one to one, one to many, Self referencing, many to many

  2. When do we use “One to One” relationships? Give an example from the real world.
    B. One name to one address

  3. 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?
    C. It is a foreign key used to join different data to a specific customer

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    D. Linking orders to a single customer / looking up orders from a single customer

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    E. to see how many orders have a particular item and how many times it was ordered.

  6. What does items_orders table do?
    F. Only to create a “Many to Many” relationship between the items and the orders.

1 Like
    • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. One to one: Customer can only make one order, order can only contain one item.

b. A person and their address for example.

  1. By connecting customers name to the addresses

  2. A costumer can make many orders and those order can contain multiple items

  3. A lot of different pizzas ordered by a lot of different people

  4. Create many to many relationship between items and orders

1 Like

1)One to One, One to Many, Many to One, Many to Many and self referencing.

2)Name to Address or Name to E-mail.

3)In order to link related data. In this case in order to link addresses and names while avoiding the problem of duplicate names and/or addresses.

4)An order with multiple items.

5)Multiple orders which contain multiple items where each item can be in multiple orders.

6)To create a many to many relationship between items and orders.

1 Like