SQL Relationships - Reading Assignment

  1. What kinds of relationships can we represent in a database?
    The various kinds of relationships represented within a database include; One to One, One to Many and Many to One, Many to Many, and Self Referencing.

  2. When do we use “One to One” relationships? Give an example from the real world.
    The example taken from the article is the customer_address, establishing a relationship between the CUSTOMERS table and the ADDRESSES table.

  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 scales relationships between the CUSTOMERS and the ADDRESSES tables, referring to the .matching record and/ or data.

  4. Give an example from the real world when one would need to use a “Many to One/One to Many” relationship.
    An example is an e-commerce website. In other words, customers make orders, orders contain items, and itemes have descriptions in many languages.

  5. Give an example from the real world when one would need to use a “Many to Many” relationship.
    An example of Many to Many relationship is the items-orders. Orders contain many items. Items can be in many orders.

  6. What does items_orders table do?
    Relationship defined as Many to Many between the items and orders.; .

Best Regards,

References

Retrieved From: https://code.tutsplus.com/articles/sql-for-beginners-part-3-database-relationships--net-8561

1 Like

@Marzio

Thank you for your contribution to our discussion. I appreciate your example about music Lp. Good work!
Best Regards,

1 Like
  1. a) One to One
    b) One to Many and Many to One
    c) Many To Many
    d) Self referancing relationships
  2. A one to one relationship could be a parking structure. Where you buy a ticket and that ticket is linked to the time you have been in there and how much you will have to pay upon exiting the park.
  3. its used to correctly identify who is linked to the address or user data.
  4. An example would be any ecomerce store where you need to bulk many different items together going to one or multiple places.
  5. When organizing orders in a kitchen you need to order multiple different things to multiple different places so that would be an example.
  6. The items_orders table shows who wants what.
1 Like

1 - One to one, One to many, Many to one, many to many and self referencing
2 - example: user name and passport number
3 - It is an identifier for the row that holds the customer name, and it is used to connect to another table, which holds the customer’s addresses, by referincing the address_id
4 - One to many = one order, many items Many to one = many orders belong to one customer
5 - relationship between customers and products. Customers can purchase various products, and products can be purchased by many customers
6 -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
  1. What kinds of relationships can we represent in a database?
    one to one, one to many and many to one, many to many, and self referencing
  2. When do we use “One to One” relationships?
    Give an example from the real world.

    my social security # and my 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?
    customer_id is the foreign key used to reference the primary key in the address table
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    a customer buys different types of apparel online
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    different customers buy different apparel online
  6. What does items_orders table do?
    create a “many to many” relationship b/w the items and orders
1 Like
  1. What kinds of relationships can we represent in a database? One to One", Many to One/One to Many", Many to Many and Self Referencing relationships
  2. When do we use “One to One” relationships? Give an example from the real world. It is used when there is only one record in one table associated with only one record in another table. For example in a student database each student has only one ID and each student ID is assigned to only one person.
  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? Customer ID is used to identify the customer and the customer address. How is it used in order to connect customers to addresses? The customer id is assigned to only one address ID
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship. Many to one would be used where many employees work for one department. One to many is used where one department employs many employees.
  5. Give an example from the real world when would need to use a “Many to Many” relationship. When you have multiple records in a table that are associated with multiple records in another table.
  6. 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. A database can represent relations between one or several things.
  • One-to-one
  • One-to-many
  • Many to many
  • Self referencing relationships
  1. One to one is good when you for instance want to know the temperature on a specific date and time.

  2. Separating the address from the customer gives the opportunity to connect other customers to the same address without having to put that data in the customer table for each new customer. It opens up the possibility to a many-to-one set-up. When each address has an ID a new customer in the customer_id table will refer to the address_id table.

  3. & 5. A good example is an online shop, where there are man persons, items and orders. A customer can place several orders including many items.

  • If you only look at the order connected to the customer, each customer can have many orders; one-to-many.
  • If you also include the items you get multiple possible purchases; many-to-many.
  1. The items_order table connects the items_id with the order_id. The order_id is in turn connected to the customer_id.
1 Like

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

  • One to One Relationships
  • One to Many Relationships
  • Many to One Relationships
  • Many to Many Relationships

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

A real world example would be an e-conmmerce business’ customers who are ordering products online. If there are two tables, one with customer names and another with customer addresses and each address can belong to only one customer, this relationship is “One to One”.

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 used to refer to the matching record in the addresses table.

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

An example of this would be an e-commerce business where one customer orders many products.

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

An example from the real world would be where e-commerce orders contain many products and each product can also be in many orders.

6. What does items_orders table do?

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

1 Like

[quote=“ivan, post:1, topic:6431”]

  • 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.
  1. We use 121 relationships in cases where there is only one direct connection between one row in one table and another row in another table. E.g. UserName and Phone No.
  • 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?
  1. The customer_ID is the Primary Key of the customer table that serves to identify each entry without ambiguity. customer_ID is actually not used to connect the two tables in the example. The primary key of the address table, called address_ID is used in the customer table as a foreign key. In this way address_ID connects the two tables.
  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
  1. The customer_ID is the Primary Key of the customer table that serves to identify each entry without ambiguity. customer_ID is actually not used to connect the two tables in the example. The primary key of the address table, called address_ID is used in the customer table as a foreign key. In this way address_ID connects the two tables.
  • Give an example from the real world when would need to use a “Many to Many” relationship.
  1. One customer, many orders.
  • What does items_orders table do?
    5.It creates many to many relationships between orders and items.
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
  2. When do we use “One to One” relationships? Give an example from the real world.
    When one key=value
    Name and social security
  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?
    This gives two tables a linking point and way to simplify and organize information
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    When one person makes multiples orders at a shop
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Making multiple
    Ordering something from Chipotle
  6. What does items_orders table do?
    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

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

An individual with a personal bank account number

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?It’s a foreign key . How is it used in order to connect customers to addresses?
It’s the customers unique identifier that can be used to retrieve their address( it serves as a link between the other customer-specific datasets)

4.Give an example from the real world when you would need to use a “Many to One/One to Many” relationship.
If we had a family of 6 that all lived at the same address - This would be a many to one relationship

In a household you might have a single mother and 3 children - this would be a one to many relationship

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

In a restaurant, multiple orders can be made by multiple people

6.What does items_orders table do?
Establishes a many to many relationship between items and orders✍🏾

1 Like

SQL Relationships - Reading Assignment

  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.

  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?
  • customer_id is necessary because addresses and maybe also the name can be the same.
  • connected to address_id (foreign key)

  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
  • one record in a table can be associated with one or more records in another table
  • each customer can have many sales orders

  1. Give an example from the real world when would need to use a “Many to Many” relationship.
  • multiple records in a table are associated with multiple records in another table
  • online-shop: customers can purchase various products, and products can be purchased by many customers

  1. What does items_orders table do?
  • creates a many-to-many relationship between items and orders
1 Like
  1. One to one, one to many, and many to many.

  2. One to one relationships are used when a record in a table is associated with one record in another table. For example fingerprints, everyone has their own set of fingerprints so only one set can be related to one person.

  3. It is used to connect data from multiple tables.

  4. A one to many relationships could be used for census data. For example parents and a list of their kids.

  5. It’s used to make a many-to-many relationship between items and orders.

1 Like

1
Relationships in a DB: one to one, one to many, many to many, self referencing.
2.
One to one: one item can belong to only one other item. Like key-value.
3.
There can be more customers with the same name. Each address can belong to only one customer.
4.
One to many = most commonly used.
One customer can make many orders, each order may contain many items, each item can have multiple features like descriptions in different languages or multiple prices in different currencies.
5.
Many to many: Car rental. A car can be rent by multiple customers, and every customer can rent multiple cars.
6.
Table items_orders: for each order it contains the customer_id, the order_date and the amount in $.
Each order_id can belong to only one customer_id, to only one date and to only one price.

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

  2. when the information just belongs to one person example: my phone number belongs to me only and my brother phone number belongs to him only. So the foreign key belongs to one person only.

3)the customer id since one to one is used for unique relationship it means ever customer id is linked to the customer address ( foreign key) in the same row.

  1. when the one person can own for example couple of different cars but each car cant belong to two people. Or each type of car can cone in lot of colors but each color belongs to one car only.

  2. each person can have 10,20 and 100 dollar bills and each 10 dollar bills can be with so many people.

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

1 Like
  1. One to one, many to one, one to many, self refrencing.
  2. When one entry can only be linked to another entry, a real worl example is a person and their passport.
  3. The customer id is a foreign key in the customer table. The customer id relates to the customer table where the customer id is a primary key and shows the record of attributes about that specific customer.
  4. One person orders multiple items from an online store.
  5. Multiple people order multiple items from an online store.
  6. It creates “many to many” relationships between items and items.
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? Give an example from the real world. --> When there is a single unique relation between two items. Eg: Social security ID for a person. Each person will have a single ID and that ID will not be the same for any other person.

  • 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 and present in both tables when there is no unique ID.

  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship. -->
    One to Many: A man has many kids as all kids have the same father.
    Many to One: Family members have one Last name.

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    –> People and stocks of companies.

  • What does items_orders table do? --> Maps items to orders (which items are part of which order) as a Many to Many relationship

1 Like
  1. 1to1, 1toMany, Manyto1, ManytoMany, SelfReferencing
  2. When a field can belong to only one other field, and vice versa. example: name and id.
  3. customer_id column is displayed in both tables, being primary key in customer table and foreign key in addresses table, hence the two tables can be connected.
  4. Names and gender (Manyto1), Names and orders (1toMany)
  5. Names and homeworks done on IvanOnTech Academy.
  6. Represents the 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

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

It is used when 1 unique cell has a unique relationship with another unique cell (cell?). a natural person monogamous marriage to another natural 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 custumors ID is an abstraction (reduced to numbers) so the computer can easily read and link the info to another table. It is the one shared element on both tables.

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

Restaurant food orders:
One customer orders two dishes.
the next day the same customers orders three dishes, only one the same as yesterday.

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

In a restaurant, total food orders to total customers.

  1. What does items_orders table do?

it connects the items to the orders, basically reiterates what item goes in what order specifically and repeating if needed.

1 Like

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

One to One Relationships, One to Many, Many to One Relationships, Many to Many Relationships and Self-Referencing Relationships

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

In a one-to-one relationship, one record in a table is associated with one and only one record in another table. For example, in a school database, each student has only one student ID, and each student ID is assigned 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 column is a unique identifier for each customer. The address_id column in the customers table is a foreign key which links each customer to their address in the adresses table.

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

In a relational database one row in table A may be linked with many rows in table B, but one row in table B is linked to only one row in table A. It is important to note that a one-to-many relationship is not a property of the data, but rather of the relationship itself.

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

A list of authors and their books may happen to describe books with only one author, in which case one row of the books table will refer to only one row of the authors table, but the relationship itself is not one-to-many, because books may have more than one author, forming a many-to-many relationship.

  1. What does items_orders table do?

Maps items to orders (which items are part of which order) as a Many to Many relationship

1 Like