SQL Relationships - Reading Assignment

  1. In SQL databases exist different types of relationships. A few of them would we:
  • One to One relationships
  • One to Many and Many to One
  • Many to Many relationships
  • Self Referencing relationships
  1. One to One relationship is used when a variable can have only one relationship with another. An example of this kind of relationship can be a drivers license ID and a person. Only one person can have one driver’s license ID and vice versa.

  2. The column called costumer_id is an identification of the customer. It is used to create a new table in order to establish a relationship between the customer and the address of the customer. In this case the customer ID turns out to be a Foreign key of the table Address.

  3. This kind of relationship happens between a commercial ship, like evergreen, and the containers that it delivers to a port. This container belongs to different customers, but only one ship does the transportation of it.

  4. Taking the previous example of the relationship between commercial ships and containers, different packages of the containers could be delivered to different ports from different countries. One container can deliver multiple packages to different countries and one country can receive multiple packages from multiple containers.

  5. It makes a relationship between the order table made by customers and the items table that are in 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.

We use One to One relationship when an entry/field can belong to only one user. For example, a Social Security Number can belong to only one person.

  1. 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 Foreign Key in the “customers” table that connects a specific/unique “customer_id” to the customer’s address in “addresses”.

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

A booking customer can book several locations, and a location can be booked by multiple customers.

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

Telecom customers are owning many phone numbers, each phone number having many services/options (voice call, data plan, voicemail, text).

  1. What does items_orders table do?

It creates the relationship between the “Items” table and the “Orders” table.

1 Like
  • One to one
  • Many to one
  • One to many
  • Many to many
  • Self referencing
  1. One to one relationships are used when a given data is unique for that particular customer. IRL example would be phone numbers. Every phone number in your phone is connected to 1 particular person.

  2. Each customer_id can be connected to only one customer and when you give every customer a id instead of using their names, it makes it easier and faster to query information. You connect the unique customer id to the address, or in this case address id, which is also done to make the process more efficient.

  3. Many customers can live on the same address if it’s an apartment, therefor it would be a many to one relationship if you don’t use the apartment number in this context. You could also as a customer add many addresses to yourself, if you order to somebody else under your account, but want the product to be delivered directly to them. That would create a one to many relationship.

  4. If you have many customers that are all creating orders with multiple items in each order. Then you can create a many to many relationship between the different unique orders and the different unique items in each order.

  5. It creates a many to many relationship between unique orders and unique items.

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

If each position in the table can refer to only one value or content, this relationship is “One to One”.
3. It is Foreign Key
3. A foreign key is a column (or group of columns) used in a relational database to link data between tables. A foreign key servers to reference the primary key of another existing table
4.

  • Customers can make many orders.
  • Orders can contain many items.
  • Items can have descriptions in many languages.
  1. One movie may have many actors, and those many actors could play in many movies
  2. tems_Orders table has only one purpose, and that is to create 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
    self referencing

  2. When do we use “One to One” relationships? Give an example from the real world.
    An individual and their passport or driving license.

  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 is a unique identifier and used as a foreign key to connect to specific customer to their address.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Buyer for a record shop purchases through one distributer that carries many different artists CD or LP’s.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Online store like amazon has many different sellers with multiple items and multiple customers buying
    many items at once from different sellers .

  6. What does items_orders table do?

    Creates a Many to Many relationship between the items and orders.

1 Like
  1. -One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. We use one to one relationship when the we have a single value, for example we have user and passport number, the passport number can only belong to one user and one user can have one passport number.

  2. Customer_id was created to simplify the table by connecting one customer to an unique id, name and address in this case is linked to an unique customer id. Customer id can also be linked to customer address id making it easier and faster to query.

  3. An example of one to many is customers and orders, one customer can have many orders.

  4. One example of many to many would be in a school between students and classes.

  5. Items_orders table creates a relationship between orders and items (many to many)

1 Like
  1. What kinds of relationships can we represent in a database?
    One – One
    One <–> Many
    Many – Many

  2. When do we use “One to One” relationships? Give an example from the real world.
    We use one to one relationships when one single data relates to only one other single data. So in the real world we would use it to draw a relationship between a fingerprint record to a person’s name.

  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 table has a customer ID, customer name, and an address ID. The customer table relates to the address table using the address ID. 1 customer ID connects to only 1 address ID.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    When you’re using a food delivery app to order food from multiple restaurants at one time.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    You’d use Many to Many relationships when drawing a relationship between two different sets of datas. When a different customers order multiple food items from multiple restaurants simultaneously and each customer’s order needs to be assigned to 1 delivery driver.

  6. What does items_orders table do?
    It creates the many to many relationship. It draws a relationship between two different tables.

1 Like
  1. What kinds of relationships can we represent in a database?
    one to one, one to many and many to many
  2. When do we use “One to One” relationships? Give an example from the real world.
    For example if each e-mail address can belong to only one user.
  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?
    With that customer table is now smaller since in that table we don’t have full customer data. With customers ID’s from separate table we can draw relations between customer and customer’s address.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    For example an item that we are selling on web shop can have many variations, and each variation can have manuals in different languages.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Many customers can make orders with multiple items inside, also each item can appear in many orders.
  6. What does items_orders table do?
    it connect different orders with items that are included in those orders.
1 Like
  1. We can have usually three kinds of relationship
    a)One to one
    b)One to many
    c)Many to many

2)Like if a John has national identity number as 12345, and Sidd has 23456 then they have unique and one to one relationship with their identity number

3)Customer I’d is a foreign key in the customer table. The customer ID is related to customer table where it is primary key that shows record about specific customer

4)Like if there is single item that is ordered by many customer or many customers order a single item

5)like a multi storey building can have many apartments and many apartments can have multiple residents

6)It is eg of many to many relationship b/w orders and item

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.
    Inputing a customer and their address into a table. Possibly for storing that on a website.
  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?
    That’s referred to as a “Foreign Key”. It pulls data from the customer_id to create an address_id and is a common tool in database relationships.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    If a customer wants to buy toothpaste along with other items, we need a table that represents one (customer) being able to buy many (items). Also vice versa, many customers buying one item.
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    Many customers are buying many items, some overlapping, i.e. toothpaste is going to multiple customers along with other items in their full order.
  5. What does items_orders table do?
    It shows us the full relationship between items and customers. It shows us the “Many to Many” relationship.
1 Like
    • One to One Relationships
    • One to Many/Many to One Relationships
      -Many to Many Relationships
      -Self-Referencing Relationships
  1. “One to One” relationships": When an entry can belong to only one customer.
    -Example: 1 person and social security number

  2. Column called customer_id in the customers table is a “Foreign Key.” It’s used to enforce referential integrity between data in two tables.
    -The foreign key is defined in a second table, but it refers to the primary key or a unique key in the first table.

  3. “Many to One/One to Many” relationship
    Consider an e-commerce website, with the following:

  • Customers can make many orders.
  • Orders can contain many items.
  • Items can have descriptions in many languages.
  1. “Many to Many” relationship.
    -A customer can order many shirts with different colors, which are also ordered by many other customers.

  2. Items_Orders table is used to create 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 many, many to one, and self-referencing
  2. When do we use “One to One” relationships?
    Give an example from the real world. We use one to one relationship when the relationship is unique to one entry or row or tuple. An example is the relationship between e-commerce user name and registered email address used for login.
  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 reason for the author to use customer_id is to store the one-to-one relationship with the customer_name, basically it works as the tuple / row. The address_id is created to separate the table based on the data type (customer name vs street address, two different thing). To connect customers to address the address_id can be used as foreign key.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Relationship between someone’s name and the registered cars this person has.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Children - parents relationship
  6. What does items_orders table do?
    items_orders table can create the many to many relationship between the items and the orders.
1 Like
  1. one to one, one to many/ many to one, many to many & self referencing relationships
    2.When only one relation is needed. Lets say there is a concert in an arena with different areas. You would have one table for ticket owners and one table for areas , both tables with a one to one relation.
  2. The addresses are defined by those numbers like a function has to be defined. In the customer section it is enough to call the address by its defined number.
  3. A King and his people
  4. Amazon
  5. It has the only purpose to create a many to many relation between items and orders

What kinds of relationships can we represent in a database?

  • One to One relationship
  • One to Many/Many to one relationship
  • Many to Many relationships

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

One attribute belongs exclusively to one entity. Example: an email address from a 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?

The customer-id, known as a “Foreign Key”, is created by the database in order to connect, corelate information between different tables.

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

In an online Store, you can have one customer ordering many items or you can have many of the same items attributed to many different customers.

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

When I’m referring an exchange crypto platform to a friend, I can give to this friend a referral link for discounts. As well, I can give access to many people my referral link for discounts.

What does items_orders table do?

It creates “Many to Many” relationship between the items and orders.

  • One to one, One to Many (and Many to One), Many to Many and Self Referencing Relationship
  • When we segregated in two tables what could be only one entity - like “Customer” and “Adress”
  • Because it will work as a foreign key to link the two tables
  • An e-commerce uses this logic
  • When we have multiple instances in both sides of the relationship; in this case we must create an extra table to deal with it
  • Creates a Many-Many relationship between items and orders
1 Like
  1. What kinds of relationships can we represent in a database?

    The following relationships 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. When do we use “One to One” relationships? Give an example from the real world.
    One to One” relationships are used when an entry belongs to only one specific person.
    E.g. Your country 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 column “customer id” is a Foreign key, which is used in databases to identify and make referrals between data that are connected/related from two different tables.

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

    When ordering items online, the customer may have multiple items - however the order belongs solely to that particular customer.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    Many customers, many items with many orders.

  5. What does items_orders table do?

    It is used to create 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 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 an entry in one table can only be link to one entry in an other table. For example, an individual and and his social security number.

  1. 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 customer_id give a specific number to a customer because more than one customer can have the same address.

This is called a foreign key keeps data organized or enforces referential integrity between data in two or more tables because more then one user may share the same address or name
A foreign key is used to create relationships between users and other tables such as the address table

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

Somebody ordering in a restaurant, one customer can order multiple times, on different days but it’s the same customer.

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

The same customer in a restaurant can order different food on different days on diferent order.

  1. What does items_orders table do?

The Items_Orders table has only one purpose, and that is to create a “Many to Many” relationship between the items and the orders.

1 Like

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?
when a customer by example has only one adress, or that the customer only can have one thing that is his
Give an example from the real world?
Peoples blockchain adress where we can send tokens to
3. In the article in the One to One section, the author has a column called customer_id in the customer table.
**Why?**Like that we can use it outside in a new table and can use this data "foreign key we use it to make relationships between tables
How is it used in order to connect customers to addresses?
it creates relationships between different tables, different customers with shorter information.
4. Give an example from the real world when would need to use a "Many to One/ One to Many relationships
with e-commerce a customer can have in different times the same article that the person ordered, like that you can track the interests that that client has and send accordingly publicity about similar articles that she could also be interested interesting to create more revenue
5.Give an example from the real world when would you need to use a Many to Many relationship.
In a festival you can have different sleeping possibilities for more than one person or group, you can have normal camping, upgrade with sleeping accomodation, luxury accommodation and so on…
6. what does items_orders table do?
create many to many relations between items and orders

1 Like
  1. One-to-one relationships, one-to-many relationships, many-to-many relationships as well as self-referencing relationships.

  2. When connecting clients with their addresses to create a user ID, for example.

  3. It connects a customers name to its address, simplifying the information to the database.

  4. When a person has multiple products they want to order, or when someone has multiple addresses.

  5. When multiple people order the same items, they can also order items mixed with other tiems.

  6. Makes an individual order, which is composed of one or more products.

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

One to One, One to Many and Many to Many. Also self-referencing ones.
2. When do we use “One to One” relationships? Give an example from the real world.

When someone has a unique identifier, like a name

  1. 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?

ID connects the customer to other info about the customer in the database

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

When a customer has ordered from multiple restaurants for example

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

When tracking virus infections in population for example

  1. What does items_orders table do?

It makes an order

2 Likes