SQL Relationships - Reading Assignment

  • What kinds of relationships can we represent in a database?
    one to one, one to many, many to one, many to many, self referencing

  • When do we use “One to One” relationships? Give an example from the real world.
    when something specific can only belong to something specific. A customer’s street address to the name of that customer is a one to one relationship

  • 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?
    because the customer_id is unique and the customer name is not unique because you can have several customers with the same name. That is why a unique customer_id is used.

  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    when a customer places an order, that order can have many items in it. This would be a many to one example. Many items to one order.
    Then you can also have one product to many orders.

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    when each order contains multiple items and each item is in multiple orders.

  • What does items_orders table do?
    it creates the many to many relationship between 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

  2. Only one customer can have one address

  3. It is foreign key used to join relationships between tables.

  4. Customers that place shipping orders.

  5. For sales and or shipping orders that contain multiple items.

  6. It creates “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

2 a. When do we use “One to One” relationships?

When an entry/field such as an address can belong to only one customer, some identifier which soley belongs to that customer, this relationship is “One to One”.

b. Give an example from the real world.

Individual people and their personal cell phone number.

3. In the article in the “One to One” section, the author has a column called customer_id in the customers table.
a. Why?

This is called a " Foreign Key " and it is used for all kinds of database relationships. Its primary role is enforcing referential integrity between data in two tables.

b. How is it used in order to connect customers to addresses?

It is a field (or collection of fields) in one table that uniquely identifies a row of another table or the same table. In simpler words, the foreign key is defined in a second table, but it refers to the primary key or a unique key in the first table. For example, a table called Customers has a primary key called customer_id . Another table called Customer Details has a foreign key which references customer_id in order to uniquely identify the relationship between the two tables.

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

This is the most commonly used type of 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.

In these cases’ we would need to create “One to Many” relationships.

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

In some cases, you may need multiple instances on both sides of the relationship. For example, each order can contain multiple items. And each item can also be in multiple orders.

An example would be: Ordering a pizza with different toppings

6. 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
  1. one-to-one, one-to-many, and many-to-many

  2. A one to one refers to relationships of two items in which one can only belong with the other
    exemple: each person has one passport, and each passport belongs to one person

  3. The customer_id is the primary key to retrieve data from the customers table and it’s unique.
    The field named “address_id” in the Customers table, is the foreign key and refers to the matching record in the Address table, for a certain customer.

  4. One to many: each customer can have many sales orders.
    Many to One: a user can have multiple photos, but each photo is owned by only one single user.

  5. Many to many: a list of books, and a list of authors. Each book may have one or more authors, and each author may have written multiple books

  6. The Items_Orders table creates a “Many to Many” relationship between the items and the orders tables.

1 Like
  • What kinds of relationships can we represent in a database?
    A: One to One, One to Many and Many to One, Many to Many Relationships & Self-Referencing Relationships
  • When do we use “One to One” relationships? Give an example from the real world.
    A: When we fill in a document with only our name & passport 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: It’s a foreign keys are used to reference a specific piece of data as the first data entry.
  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A: If we purchase items on Amazon for example, we may be purchasing more than one item, but it’s still linked to only one user.
  • Give an example from the real world when would need to use a “Many to Many” relationship.
    A: A fast food ordering app would receive many orders from many different customers for many different food shops.
  • What does items_orders table do?
    A: It’s sole purpose is to create a many to many relationship between the items and 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.
    customer email
  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? it is a number, which can be unique, but more than one person can have the same name. This id can be connected with things like orders
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    many to one, orders for 1 particular item
    one to many 1 user is a member of different social media groups
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    each of multiple purchases have multiple things bought, and each of multiple things bought can be in multiple purchases
  5. What does items_orders table do?
    makes a many to many relation of items and orders
1 Like

A1. one to one, one to many, many to one, many to many and self referencing
A2. A user and email ID
A3. It is a unique key that identifies customer
A4. Many students can enroll to one course. One Lecturer gives class to Many students
A5. Shop selling many items to many people
A6. Contains relationship between items and orders.

1 Like
  1. One to one, one to many, many to many, self reference.
  2. When each element of a table is related with a single element of another table
  3. This is a way to relate the customer_address to customer_name directly, is called foreign key.
  4. For example, in Amazon, each user has each own shopping basket with none, one or multiple products inside, but each bastket only has one user related to it.
    5.It creates a many to many relationshipo between products and orders
1 Like
  • One to one

  • One to many

  • Many to one

  • Many to many

  • Self-referenncing relationships

  1. One to one is used for example in customer database relationship, when an address or some other identifyer can be related to the customer.

b) People and their phone-numbers in an online address book. Or emails

  1. customer_id is used to for all kinds of database relationships, it is used to refer to data between two tables. Also called ‘‘foreign key’’’.

  • When a customer has an order history.

  • An order with many items

  • Customers past appointments

  1. Many to many, lets you relate each row in one table to many rows in another table and vice versa.
    Can be used to order something with different ingredients online, pizzatoppings etc. When many customers are ordering the same items. When an employee has many skills that is shared by more employees.

  2. items_orders table is used to create a many to many relationship between the items and the order.

1 Like
  1. One to One Relationships
    One to Many and Many to One Relationships
    Many to Many Relationships
    Self-Referencing Relationships
    1. A unique user and their address.
      3)The customer_id column in the customers table is used to uniquely identify each customer and is used as a foreign key in the addresses table to identify which customer belongs to each unique address.
  2. A Customer can have many items on and orders but the order can only belong to one customer.
    1. Many customers, many orders, one item, that many customers order, many times.
      6)Records all order details such as customer, date and amount. It helps store owner identify which order is made by which customer by using keys: customer_id and order_id.
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.
Is used when each item of the row, is distinctly linked to another item in other table, example address id and person 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?
It is a Foreign Key, and it is used to join relationships between tables
The Field named “address_id” in the “Customers Table”, that is the foreign key, and refers to the matching record
in the “Address table”, for a certain customer

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

When a customer can make many orders, and this orders can contain many itens, and this itens can gave different descriptions in many languages

*5 Give an example from the real world when would need to use a “Many to Many” relationship.
One football team may have many players, and those many players could play in many teams.

*6 What does items_orders table do?
The items_order shows the relationship between the order_id and item_id, is the thable forms Many-to-Many relationship between items and 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.
    Name and address for a person or customer. If each address can belong to only one customer, this relationship is “One to One”.

  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 called a “Foreign Key” and it is used for all kinds of database relationships for example an Address ID and Customer Table.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    An e-commerce website for instance:

  • Customers can make many orders.
  • Orders can contain many items.
  • Items can have descriptions in many languages.
  1. Give an example from the real world when would need to use a “Many to Many” relationship.
    In an eCommerce website each order can contain multiple items. And each item can also be in multiple orders.

  2. 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.

2 Likes
  1. What kinds of relationships can we represent in a database?
    One to one
    One to many
    Many to many
    Self referencing

  2. When do we use “One to One” relationships? Give an example from the real world.
    Person - Passport
    Only this passport can be for this 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? How is it used in order to connect customers to addresses?
    It’s a foreign key to help link data between two tables. It helps reference the primary key of another table like customer_id to address.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Employer to Employees
    People to Address
    Computer to Files
    Library to Books

An employee can be tracked to one Employer

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

  2. What does items_orders table do?
    Many items to many orders relationship

1 Like
  1. What kinds of relationships can we represent in a database?
    1-1, 1-many, many-1, many to many, self referencing relationships
  2. When do we use “One to One” relationships? Give an example from the real world.
    We use it to link the information with another unique one for example; any letter on the mail Name-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? To index the information we give a foreign key to ID like i said in #2
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship. Could be a delivery list and could be a supermarket bill
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    We can find that on a payroll accounting books or law enforcement database os.
  6. What does items_orders table do?
    Create a “Many to Many” relationship
1 Like
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self-Referencing Relationships
  1. When we have only one relationship between the entry in a table
    ex. ID or Passport numbers of each person

  2. Because there is only one customer_id per customer in the table which also does match only one address_id per customer.
    The **customer_id in the customer table is called " Foreign Key "/ ``primary key and they are used for all kinds of database relationships entries like address details or bank account details, allergies etc.

  3. Many Students can apply to only One Moralis Academy and One Academy Moralis has many classes and subjects that many lecturers beside Ivan are teaching each Student.

  4. Many Students In Academy Moralis can learn about Many Subjects and get many Diplomas in Blockchain technology.

  5. Items_orders table determine Many to Many relationship between the “order_id” table and “item_id” table.

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

We can represent One-to-One, One-to-Many, Many-to-One, and Many-to-Many relationships in a database.

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

We use “One to One” relationships when one and only one piece of information can belong to one item or individual. In the real world, for example: for new born babies in a hospital, any new born baby can have only one mother.

  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 used in the table to connect the customer to the customer’s name. It is used along with address_id to connect the customers to their addresses.

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

In the real world, a tool box may have different sets of tools-star screwdrivers of different sizes, flat screwdrivers of different sizes, , allen keys of different sizes, spanner sets, etc., etc., and this can make it necessary to use a “Many to One/One to Many” relationship.

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

Comparing a tub of mixed nuts and a tub of deluxe mixed nuts: One tub of mixed nuts may contain several types of nuts and several of these nuts, for example, cashews, almonds, and pecans can be found in the tub of deluxe mixed nuts.

  1. What does items_orders table do?

The items_orders table pairs off the order_id with item_id and ensures that each order contains the correct items.

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 item or specofied thing (eg:address) can belong to only one other specified thing (eg:customer), this relationship is “One to One”.
Each individual customer has one specific address that only belongs to that one customer.

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 refers to the matching record in the Address table. This is called a “Foreign Key” and it is used for all kinds of database relationships.

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

This is the most commonly used type of 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.

Each customer may have zero, one or multiple orders. But an order can belong to only one customer.

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

In some cases, you may need multiple instances on both sides of the relationship. For example, each order can contain multiple items. And each item can also be in multiple orders.

6. 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
  1. one-to-one, one-to-many, many-to-one, many-to-many and self-referencing
  2. When there is only one entry in table A that relates to an entry in table B and no entries can relate to more than one entry in the other table. An example is a person ID to unique biometric information (eg. retina scan)
  3. The customer ID can be referenced in other places in the database and easily refer back to the customers table and find the corresponding information without having to search and compare strings. It is also unique and prevents problems when two customers happen to have the same name.
  4. If relating a mother to their children, they could have many children but a child only ever has one biological mother
  5. If relating people to the sports teams they support, an individual sports team can have many supporters and an individual person can support multiple sports teams
  6. It relates orders to the items that are on that order.
  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” relationship? Give an example from the real world.
    Answer: example if each address can only belong to only one customer (very uncommon)

  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 separates into another table with customers and addresses
    How is it used in order to connect customers to addresses? -The addresses is the foreign key

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Answer: This is commonly used for e-commerce websites

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Answer:When dealing with multiple order like Amazon

  6. What does items_orders table do?
    Answer: Has only one purpose and that is to create a “many to many” relationship between the items and orders

1) Database Relationships?

  • One-to-One, One-to-Many, Many-to-One, Many-to-Many, and the ol’ Self-Referencing. It’s like a social network for data.

2) One-to-One? Real-world?

  • Think Social Security numbers. One SSN, one person. No sharing allowed.

3) customer_id in customers table?

  • It’s the link, man. Foreign Keys make sure customers and addresses are tight.

4) Many-to-One/One-to-Many?

  • College scene. One course, multiple classes. Or flip it—many profs for one course.

5) Many-to-Many?

  • Students and classes. It’s a free-for-all. Everyone’s mingling.

6) items_orders table?

  • Matchmaker for “order_id” and “item_id.” Makes sure they play nice in a Many-to-Many setup.