SQL Relationships - Reading Assignment

  1. One to one relationships; many to many relationships; self referencing relationships
  2. We use one to one to define a basic correlation between one piece of info and the next. For example one address per customer.
    3.This refers to the matching order in the address table, also called a Foreign Key. Each address can only belong to one customer.
    4.One person can have multiple positions within a company. Or in another example, many
    species of shark can live in one reef, and one reef can hold many sharks.
  3. Many species of fish can live in a reef, and within than reef, there can be many varieties of the same species of fish.
  4. An order item is used to create “Many to Many” relationships.
1 Like

Hello @JCrypto, hope you are great.

Yes, both replies of your answer can be seen perfectly.
Good answers btw. :clap:

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

  1. One to one relationships
    many to one relationships
    one to many relationships and
    many to many relationships
    self referring relationships.

  2. .When you have different tables and every data specification belongs maximum only to one data specification in the other table.
    ex. an individual and it’s national id number.

  3. a. ‘customers_id’ is referring to all matching records from one table onto another table. It’s called a foreign key. it’s making it easier to refer to a column from another table.
    b.The foreign key is an entry that will be put in the second table you want to connect with. this in order to establish relationships between different data.

  4. one building can have multiple owners - but one building can also have one owner.

5 many to many:
The data is connected by multiple other data on each side of the data.
so: each order contains multiple items. ( sushi, sashimi, miso soup). But each item has been ordered in many orders. Sushi has been ordered by order x,Y, Z, Sashimi by order X,R, O, etc…

The items_order has as purpose to make a table to connect the many to many relationships

1 Like

Reading Assignment: SQL Relationships

One-to-One, One-to-Many, Many-to-Many

We use a one-to-one relationship when an object relates to another single object of a certain type. For example a person to national ID number relationship. Each citizen has one nation ID number, and each nation ID number represents only one citizen.

The customer_id column is a unique identifier for each customer. It could be used to reference a specific customer from another table, like orders. In the article’s example customer_id is not used to connect customers to addresses, instead the customer table includes an address_id for each customer. That address_id is used to link the customer to the corresponding address in the address table.

An example of a one-to-many relationship could be people and their pets. Each person could own zero, one, or more (many) pets but each pet is owned by one unique person.

An example of a many-to-many relationship would be students and courses. Each student can be enrolled in multiple courses, and each course may have many students.

The items_orders table maps order_ids to item_ids. It shows which orders contain certain 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.
    If an attribute can belong to only one entity, this relationship is “One to One”. Example: car - license plate 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? How is it used in order to connect customers to addresses?
    As a “Foreign Key” it applies for all kinds of database relationships. It connects datas of two tables.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    One Family can have zero, one or more children. Each child has a hobby or more. Hobbies maybe different.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Each of the hobbies of the children needs different accessoires, but some of the accessoires might be part of multiple hobbies, like a ball or protectors.

  6. What does items_orders table do?
    it creates “Many to Mnay” relationships between the items and the orders

1 Like

QNS 1. What kinds of relationships can we represent in a database?
ANS: We can represent

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

QNS 2. When do we use “One to One” relationships? Give an example from the real world.
ANS:WE use “One to One” relationships when it only belongs to one entity. For example, the house address of your house.

QNS 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?
ANS: This is called a “Foreign Key” and it is used for all kinds of database relationships. It connects data across two tables.

QNS 4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
ANS:An Online shop where they sell more than one variety of item. Each Item has different attributes like for e.g colour, size.

QNS 5. Give an example from the real world when would need to use a “Many to Many” relationship.
ANS: Each of the online shop items will need different parts to make it workable.

QNS 6. What does items_orders table do?
ANS: It was use to create a Many to Many relationship between 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

2.When do we use “One to One” relationships? Give an example from the real world.
One person has one passport, and the passport is owned by one person.
One person has one name, and that name belongs to one person.
A person owns one dog, and the dog is owned by 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? How is it used in order to connect customers to addresses?**
Because it is the primary key. And it is going to be used as a foreign key to connect with the address.

4.Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
Customers can make many orders.
Orders can contain many items.
Items can have descriptions in many languages.

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

6.What does items_orders table do?
It exists to make 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. “user” and “address”
  3. The Customer ID is then later used in other places, it’s called a “key” or a “foreign key”
  4. Many-to-one could be on an E-Commerce website, where one order contains many items for instance
  5. Many-to-many could be on another E-Commerce website, where many items occur in many orders for instance
  6. The purpose of the items_orders table is to create relationships between the items and the orders
1 Like
  1. The relation types represented in a database can be, One to One, One to Many, Many to One, Many to Many and Self Referencing Relationships.

  2. A database containing current passport information could be a one to one relationship as each person would only have zero or one current passports (for a given country).

  3. This question is slightly mixed up as in the example the address_id was actually used as a foreign key to connect the customers table to the address table.

  4. The arguably most common use online would be for online shopping where an order table would contain all the orders created in a one to many relationship between customers and orders…

  5. Again used in e-commerce an order items table would be a many to many relationship where any give item could appear multiple times in different orders.

  6. The items_orders table joins together each unique order, contained in the orders table with the one or many items which are contained in each order referenced in the items table.

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.
    In a one-to-one relationship, one record 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…

  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?
    customer_id uniquely identifies each customer (primary key) which is used to connect to other tables.

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

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    A many-to-many relationship occurs when multiple records are associated with multiple records in another table. For example, a many-to-many relationship exists between customers and products: customers can purchase various products, and products can be purchased by many customers.

  5. What does items_orders table do?
    Create a “Many to Many” relationship between the items and the orders.

1 Like

1:

  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
    2:
    A one to one relationship is where one piece of data is associated with one other. Such as ID number and username.
    3:
    Its a foreign key. It can be used to connect data from two different tables.
    4:
    One customer may make many orders or one order can have many items.
    5:
    A course can have many students. A student can have many courses.
    6:
    It creates many to many relationships between items and orders.
1 Like

Here are the answers:

  1. What kinds of relationships can we represent in a database? They are: 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.
    For example, if we want to link email address just with one name for registration purposes, this will be one to one, or phone number with a name, bank account number with the name or Passport ID with the name, all those examples can be used as “One to One relationships”
  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?
    In order to link customers to an address id especially if they input a different id, for identification
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many to one can be used for example while ordering online at the same app/website multiple times and then just be filtered by user id with many other orders id (i.e uber eats, amazon, aliexpress etc)
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    The most common example can be an example of linking multiple students for multiple classes with university or Ivan on Tech Academy :wink: .
  6. What does items_orders table do? this is an example 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

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

A social security number could classify as one-to-one because each number can belong 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? How is it used in order to connect customers to addresses?

So that the customer_id in the Customers table can refer to the matching record (the address_id) in the Address table. The address_id in the Customers table would in this case be considered a Foreign Key

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

A One to Many relationship would need to be created for a university considering:

  • Students can study different programs.
  • Programs can contain many courses.
  • Courses can be taught by many teachers.

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

A Many to Many relationship would need to be created for a university considering:

Each course can contain multiple students, but each student can also take multiple courses.

6.What does items_orders table do?

The Items_Orders table’s only purpose is to create a “Many to Many” relationship between items and orders.

1 Like
  1. What kinds of relationships can we represent in a database?
    => 1-to-1, 1-to-Many, Many-to-Many, Self referencing
  2. When do we use “One to One” relationships? Give an example from the real world.
    => table A references max 1 row in table B, ex.: family tree: table family, column father -> people 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?
    => customers_id contains an unique value in that column to identify a customer row. It can be used from another table to select a customer. To select an address in the address table the address_id fields in both tables are used, not the customer_id field of the customer table.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    => One-to-Many: (Business) Customer with several addresses: physical, Postal, Delivery-of-goods;
    => Many-to-One: Several employees working in the same location (room)
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    => Many-to-Many: Several Teachers to several Students (grouping)
  6. What does items_orders table do?
    => records the relation between items and orders allowing many-to-many relations: 1 order to many items and 1 item to many orders.
1 Like
  1. Types of relationships:
    One to One Relationships
    One to Many and Many to One Relationships
    Many to Many Relationships
    Self Referencing Relationships

  2. One-One: the field belongs to one person and a one-one relationship.
    Your cell telephone belongs to one person.

  3. The customer_id is a foreign key and used to ensure referential integrity for the data.

  4. Example of one-many / many-one is going to the store to apple juice. You have many different types of apple juice to choose. They are all juice but they are from different brands.

  5. Many-many is several clients buying different types of juices and there are many brands for each juice type.

  6. Items_orders is used to determine the many-many relations between the order_id table.

1 Like

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

2 my friend A has the phone number 1111111
my friend B has the phone number 2222222

3 to assign a number to each customer and cross the information from the adress to the customer id

4 when going to a shopping site to buy some shoes we choose the brand among many the color among some the number of the shoe, we choose with which card to pay the page can be different languages, and the currency with which we will pay

5 on a job site we were able to choose the business area we were looking for

6 Items_Orders serves to create a many to many relationship

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

a. One to One Relationships (not common)
b. One to Many/Many to One (most commonly used relationship)
c. Many to Many
d. Self-Referencing Relationships/reading assignment stopped here

  1. When do we use “One to One” relationships?

When an identifier can belong solely to one customer.

Give an example from the real world. A customer and their specific residential address

  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?

This is referred to as a “Foreign Key” in the Customer Table. The customer_ID is a “Primary Key” and displays attributes about this specific customer.

How is it used in order to connect customers to addresses? It creates a relationship between the customer and the residential address associated.

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

In respect to University, you have the students, you have the different courses the University offers, but a single course can have many classes within the course.

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

Many customers, many orders, one item, that many customers order, many times.

  1. What does items_orders table do? It connects customer to the items bought by the customer ID
  1. “One to one”, “One to many”, “Many to One” and “Many to Many”.
  2. Person and it’s DNA
  3. To create a relationship between the adress and the customer, wher “customer_ID” is the primary and displayes the attributes of this customer such as adress
  4. Class of a specific year can have several students but only happens in a specific year
  5. An item on an online store can be pruchased by many customers but also be ordered together with other products
  6. manytomany relationships between the item and the orders
1 Like
  1. One to One, One to many and many to one, many to many, self referencing
  2. When an entry such as (city of birth) will only belong to one unique person. Such as members of a bank and each members account number
  3. A Foreign Key A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables. It acts as a cross-reference between tables because it references the primary key of another table, thereby establishing a link between them.
  4. Many to one / One to many which is the most common database relationship can be shown when you have a website for online ordering and Customers can order more then once, with many items, Items with different prices, Different descriptions for different languages
  5. A typical 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 Many to many relationships between the items and the orders
1 Like

1What kind of relationships can we represent in a database?• One to One• One to Many and Many to One• Many to Many• Self Referencing
2. When do we use “One to One” relationships? Give an example form the real world.When an attribute in a table matches an attribute in another table. For example, a table of a Customer name in one table matched the customer name in another 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?Because there is only one customer id per client that matches the only one address id per client.
4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
Customers can buy more than one widget in an online purchase or multiple customers can buy the same widget.
5. Give an example form the real world when would need to use a “Many to Many” relationship.
Many different Custumers can buy many multiple widgets on an online purchase.
6. What does items_orders table do?
It creates the relationship between the Items table and the Orders table, both sides of this table.

1 Like