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.
    When trying to find address for a user.

  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 is the foreign key and it’s used to connect customers & address tables to get the address per customer ID.

  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Customer ID might have multiple orders.

  2. Give an example from the real world when would need to use a “Many to Many” relationship.
    Orders might have multiple items, and items can be in multiple orders.

  3. What does items_orders table do?

It gives all the items related to order IDs.

1 Like
  • What kinds of relationships can we represent in a database?
    One to One relationships. One to Many, Many to One and Self Referencing
  • When do we use “One to One” relationships? Give an example from the real world.
    When there can not be more than one relationships between an entry.
    Each unique identifier like a SSN can be associated with one 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?
    To create a relationship between the customer and the address.
  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A person can have one name but many email addresses
  • Give an example from the real world when would need to use a “Many to Many” relationship.
    A student may attend many classes and each class can host many students.
  • What does items_orders table do?
    Used for Many to Many relationship between the “order_id” table and “item_id” table.
1 Like
  1. What kinds of relationships can we represent in a database?
    One to one, one to many, many to many, and self-referencing
  2. When do we use “One to One” relationships? Give an example from the real world.
    One person has one birthday
  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 customers table has a customer_id so additional information about the customers, not needed in the customer table, could be stored in another table in the database. The customer_id is matched to an address_id which acts as a 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.
    Mothers can have multiple children, while multiple children only have one mother
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Siblings
  6. What does items_orders table do?
    Creates a 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. a relationship between the Customers table and the Addresses table. If each address can belong to only one customer, this relationship is “One to One”.

  3. A field named “address_id” in the Customers table, that refers to the matching record in the Address table. This is called a “Foreign Key”.

  4. For example an e-commerce website.
    Customers can make many orders.
    Orders can contain many items.
    Items can have descriptions in many languages.

  5. For example, each order can contain multiple items. And each item can also be in multiple orders.

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

1 Like
  1. There are 4 kinds of relationships in a database:

a) One-to-One relationship: this relationship exists when each record in one table relates to only one record of the other table. This is not a common kind of relationship in a database, however, it is good to use for security purposes.

b) One-to-Many or Many-to-One relationship: this relationship exists when each record of one table can be related to one or more than one record of the second table. This is the most common type of database relationship.

c) Many-to-Many relationship: this relationship exists when each record of one table can be related to one or more records of the second table, and a single record of the second table relates to one or more records of the first table.

  1. One-to-One relationship is used when each record in one table relates to only one record of the second table. For example, each user/customer has a passport with a unique passport number.

  2. Customer_id is an attribute that holds records of each unique customer. It is used with the Primary Key, i.e., Address_id, to identify a single row with a primary key value in a table to form a relationship with the other table.

  3. A customer can place multiple orders, i.e., one customer, many orders, - One-to-Many Relationshiop. On the other hand, those orders belong to just one customer, and thus it forms Many-to-One relationship.

  4. A customer can buys multiple products, and each product can have multiple orders.

  5. items_orders table forms Many-to-Many relationship between items and orders.

1 Like
  1. One to one, One to many/one to many, Many to many.

  2. Person and their Mobile no.

  3. It is simpler to use ID as the Foreign Key to another table.

  4. Name - Item ordered / items - Name

  5. Names of person(s) - Make of car owned / Makes of cars - People who own them

  6. Shows the relationship between all of the items and all of 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.
    Amazon: Name—>Mailing 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 represents a foreign key that connects customer name t the address.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    UPS data base. Multiple packages can be for the same address and customer, multiple packages to same address for different people living at the address. Multiple addresses multiple packages same customer.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    Restaurant point of sale. You would want to know check#, Check items, check totals, item totals, credit card payment, customer name, purchase date, times visited in the last month.

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

One to One Relationship
One to Many and Many to One Relationship
Many to Many Relationship
Self-Referencing Relationship

  1. We use “One to One” relationship when each item has a unique identity. Example: Thumbprint and People in a country database. Each person will be matched with one thumbprint.

  2. Customer_Id is used as a foreign key that shows a relationship between two tables. The customer_id can be used to access the address of a customer.

  3. Many to One can be in an Ice-cream shop database; many customers can order a single flavour of an ice-cream. Similarly One to many could be where one customer orders different flavours of ice-cream.

  4. When ordering a pizza you can order a particular kind of pizza while the order can contain other items like chicken wings, drinks, etc. Thus same items can be contained in another person’s order of a different kind of pizza.

The items_order shows the relationship between the order_id and item_id

1 Like
  • One to one Relationships
  • One to Many and Many to One relationships
  • Many to many relationships
  • self-referencing
  1. I think when we get sim card for a company with contract our number is belong to our name so is one to one relationship.

  2. So each customer has a number ID in companies database (customer table). So foreign keys are used for all kinds of database relationships. That is how we connect customers to addresses.

  3. When one person speaks more than 2 languages.

  4. In a Library

  5. To create 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, and Self Reference Relationships.

2 Its used when we have to use an extra table of information, for example, when a person signs a contract, it is one to one relationship.

3 It refers to the matching record in the Address table. This is the “Foreign Key” wich creates the relationship between the tables.

4 On a restaurant, a table can have many orders.

5 In a shop can be many workers, and many workers can rotate the work position during the day.

6 The items_orders table its made to create a “Many to Many” relationships between the items and the orders.

1 Like

Hey guys! Who is loving studying databases? My OCD, that’s who.

  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.
    Not very commonly used, an example of one-to-one would be in the case of having a table for customers and their email 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?
    Having a customer ID number makes it possible to use it as a reference when connecting tables with information related to that customer.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    More commonly used, an example of one-to-many relationship use case for databases would be repeat customers buying multiple items across many different times.
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    In the case fo multiple items in a single order and multiple orders you would use a many-to-many database structure. Amazon most likely uses this.
  5. What does items_orders table do?
    It creates a many to many relationship between items and the 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

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

A person can have one home address.
[Person] <——> [Home 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?

The customer_id is a way to associate a number with the customer and their data.

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

Mother to Children

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

Sibling to Sibling

6. What does items_orders table do .

Allows items to contain orders and orders to contain items

1 Like
  1. What kinds of relationships can we represent in a database?
    1 -1, 1 - many, many - 1, many - many.
  2. When do we use “One to One” relationships? Give an example from the real world.
    Customers may or may not have an address. Separating may save you some space.
  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?

    tables can reference a customer_id, almost like a variable.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    one person can have multiple addresses.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Roblox has a lot of groups and a lot of people in the groups.
  6. What does items_orders table do?
    links multiple items to multiple orders.
1 Like
  1. There are one to one, one to many, many to one, many to many, and self referencing relationships.

  2. A one one one relationship is when a record on one table is associated with one unique record in another table. An example is a user an their password.

  3. The customer ID acts as a bridge between the two tables and the customer data that they hold.

  4. A one to many relationship can e commerce website were one person can place many orders.

  5. A many to many relationship can be creating a schedule that involves multiple students and classes.

  6. It allows multiple orders to contain multiple items. In other words, it enables many to many relationships. Otherwise, only one to one, one to many, or many to one orders would be allowed.

1 Like
  1. What kinds of relationships can we represent in a database?
    Mainly : one to one, one to many, many to many
  2. When do we use “One to One” relationships? Give an example from the real world.
    One person has one and only one SSN
  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 field enables to identify uniquely a customer. This is the primary key (unicity constraint) for customer. Each customer id is linked to an address id in order to connect them. As a result, one customer will have one and only one address.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A bank account can have several holders (for a couple, for instance), many people can have the same bank account.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    A people can have multiple crowdfunding investments. One real-estate project can have many investors.
  6. What does items_orders table do?
    It enables to know list of items per orders, cause the relationship between it.
1 Like
    • One to One;
    • One to Many, Many to One;
    • Many to Many;
    • Self Referencing Relationship.
  1. Employee name and Worker ID.

  2. It refers to a matching record in the customer table.it is use for all kinds of Relationship database.

  3. Many items for one order.

  4. Multiple orders contain multiple items.

  5. Shows items in a specific order.

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

2.a Customer to adres relationship.
b. One customer has one adres.

3.a. This Id represents a certain customer in the database.
b. The customer id is connected to a certain adress in a table.

  1. Customer can make many orders
    Orders can contain many items
    Items can have descriptions in many languages.

  2. Order with multiple items and each item in multiple orders
    Pizza with different toppings would be an example

  3. Many to many relationship between items and order

1 Like

1 One to one, Many to one, One to Many, Many to Many and self referencing
2 One customer has one social security number, a table with these two pieces of info represents one to one.

3 A Foreign key is used, it is used to show integrity between tables, for example each customer has a name and customer id, in another table customer id is used to reference customer, this creates a relationship between the two tables.

4 A customer can rent many videos, but each video has a rental id which is unique…one customer can rent many videos but each of the many videos is with one customer.

5 A customer can have as many phones as they want, many phones can belong to different people

6 Connects orders id and items id in an many to many relationship.

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.

only one relationship in between the entries
customers and their(delivery ) 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? How is it used in order to connect customers to addresses?

as there is only one customer_id per client that matches the only one address_id per clients is used as a foreign key.

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

customers with on or multiple orders and every order belongs ( matching ) just one customer

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

each order can contain multiple items. And each item can also be in multiple orders.

  1. 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
  1. One to One, One to Many/Many to One, Many to Many, Self-Referencing
  2. When we use only one Table. It can only show the relationship between one row and one column. Example: Restaurant Menu: Rows are the meals and Columns are the properties (Description, Ingredients, Price). You can only reference one meal with one property.
  3. This Id can be used in other tables to cross-reference to the customer. Like this you don’t have to write out the customers full name every time - saves space and time and money and makes the whole system more efficient. If you place an order, the order itself will contain information such as its own id, the item(s) purchased, the time and also the customer - here you would input the Id.
  4. If I had five cars
  5. If I had ten children that would all drive all five cars
  6. It matches an item with an order
1 Like