SQL Relationships - Reading Assignment

  1. One to one, one to many, many to one, many to many and self referencing.

  2. Entering data for a new member at a gym with their Name, Phone, Email, Address

3 It can be used to subtract the information from the user and this is done to create a relationship between the customer and addresses

4 An example could be ordering from a nike online store which can take many relationships like Shoe, Size, Quantity etc

5 A music concert online store that would have many customers ordering many different types of tickets and quantities with upgrade etc

6 The Items_Orders table creates a many to many relations as links the Item purchased with the with the order number for the customer who purchased the products.

1 Like
  1. What kinds of relationships can we represent in a database?
    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.
    When one entry can only belong to one client.
  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 links the 2 items in different tables. It creates the relationship between 2 tables.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A table that links for example email addresses to people. One person can have many addresses but one address can only be of one person
  5. 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.
  6. What does items_orders table do?
    t is only used to determine the Many to Many relationship between the “order_id” table and “item_id” table.
2 Likes

What kinds of relationships can we represent in a database?

There are several types of database relationships including:

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

A real world example of a “One to One” relationship would be a Name and Address

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 “ custumer_id ” is used to give each

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

A real world example when one would need to use a “Many to One/One to Many” relationship would be and online store where customers can make many orders. Orders can contain many items and tems can have descriptions in many languages.

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

A real world example when one would need to use a “Many to Many” relationship would be an online store and a customers has purchased multiple items

What does items_orders table do?

An “ items_order ” 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 one, Many to many, Self Referencing.

  2. Name to Social security number.

  3. This is a way to simplify the information by using a foreign key to identify what customer is purchasing what.

  4. Customers can make many orders, orders contain many items.

  5. Each order contains multiple items, also an item can be in multiple orders.

  6. To 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. One to One relationships is used when we want to connect one item to another item (usually connecting same item to different categories). An example from the real world could be Name-Student ID-GPA.

  3. This is called a “Foreign Key” and it is used for all kinds of database relationships. A foreign key is a column or group of columns in a relational database table that provide a link between data in two tables. It acts as a cross-reference between tables.

  4. A real world example of Many to One/One to Many could be e-commerce website. Customers can make many orders, but an order can belong to only one customer.

  5. A real would example of Many to Many relationship, students and classes. A student can register for many classes, and a class can include many students.

  6. items_orders table 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 - one
    one - many and many -one
    many - many
    self referencing

  2. When do we use “One to One” relationships? Give an example from the real world.
    when the record belongs exclusively to one particular entry
    We use one - one relationship in a case which we allow a particular entry to be linked to a particular data which can only belong to that particular entry and not with any other ones. Say Mr. A owns a xxx Telephone number. This xxx number can only belong to Mr. A

  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 called a “Foreign Key” and it is used for all kinds of database relationships. It matches one data to the linked data in two tables.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Say a food order Mr. A and Mr. B place food order to the same restaurant and orders though are to different persons at different address may have an overlapping item(s).

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Take the previous example, one food item may be ordered by 10 different customers at different time of the day. And the common order may have special additions (items).

  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 relationships.
    2.We use one to one relationship when we have one piece of data that is related to only one other piece of data. For example each Facebook use has only one profile picture connected to him. So in the database we have one use and one profile picture, a one to one relationship.
  2. Sometimes there might be two people with the same name, so a customer_id can help distinguish between them and also provides a shorter input for the name. Also each customer_id is connected to an address_id.
    4.Many users can be part of one group, so that would be a many to one relationship in a database. On the other hand one user can be part of many groups and that would be one to many relationship.
  3. Many users can be part of many groups and that is an example of many to many relationship…
  4. Creates many to many relationship between items and orders.
1 Like

.One to One relationships
.One to Many & Many to One relationships
.Many to Many relationships
.Self - Referencing relationships

2 One to One relationships are used where a unique entry can only be referenced to another unique entry. Me to my passport number.

.The database id reference is known as a “foreign key” it is used to differenciate between fields on the database, such as “customers”, “address”, “height”, “age”.
. Each field has a corresponding “id” which the database uses to to cross reference ,ie id _101 “name” to id_201 “address”

  1. Example facebook many people comment on a post, but the comments belong to that one post.

5.Customers can purchase many products, and products can be purchased by many customers.

  1. It creates 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, Self Referencing.
  2. When an entry field is unique to one item and cross referenced to another item unique to that field. eg. standard hotel room pulling data from the fireplace table showing standard room numbers with fireplaces for the query.
  3. The customer_id field is used to link to the address_id for the query. The address_id is the foreign key in the customer table.
  4. Standard room vs Rate Plans. a search on one standard room can produce several rate plan options, for the same date.
  5. to link a Guest name, to a room type, to a rate plan.
  6. the Items_Orders table creates 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.
    If each data can belong to only one customer, this relationship is “One to One”. Example: DNA.
  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.
  3. 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.
  1. Give an example from the real world when would need to use a “Many to Many” relationship.
    Food home delivery order.
  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.
1 Like

Q1. What kinds of relationships can we represent in a database?
A1. one to one, one to many, many to one, many to many and self referencing.

Q2. When do we use “one to one” relationships? Give an example from the real world.
A2. My name to my physical address.

Q3. In the article is 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 address?
A3. the customers id is custom to one person only and a address id connect with an address the can be used by more then one customer id. but the address id has its own custom address connected to it.

Q4. Give an example from the real world when would need to use a “many to one/one to many” relationship.
A4. Many to one can be used for a list of students to one school. One to many can be used with a student to a classroom of students.

Q5. Give an example from the real world when would need to use a “many to many” relationship.
A5. Many to many can be used in a group of students in a sport competition.

Q6. What does items orders table do?
A6. items orders establish links for relationships.

1 Like
  1. In a database we can represent the following kinds of relationships -
  • One to One
  • One to Many (and many to one)
  • Many to Many
  • Self referencing relationships
  1. We use one to one relationships when one unique entry is only linked to another single unique entry. A real world example would be a persons customer number with a shop.

  2. customer_id is a unique entry that can reference all the information about just this one particular customer. The customer_id can be used to find the matching customer_address on that row.

  3. an example of a One to many relationship would be a ‘one’ customer who can place ‘many’ orders.

  4. An example of a Many to Many relationship would be ‘many’ different orders that can contain ‘many’ different items.

  5. The Items_Orders table creates 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 and Self Referencing Relationships.

  2. A unique user like a student having a unique student ID.

  3. Because each customer have a unique customer id that matches the only one adress ID per customer.

  4. A student can work on more than one project.

  5. Customers can purchase various products, and products can be purchased by many customers.

  6. It creates a many to many relationship between items and orders.

1 Like
  1. the kind of relationships that can be represented in a database are, one to one, one to many / many to one and many to many also self referencing relationships
  2. one to one is used when you have a table with for example, just name and address one entry that belongs to only customer
  3. a customer_id in the customer table this is a foreign key for referencing between data tables. this connects customers to their addresses by having a column in the first table called customer id which is linked soley to one customer once a query is made into customer id, the other table is referenced and brings the result of the details of that customer.
  4. an example of one to many/many to one is orders made by a customer, one customer can make many orders and many orders can contain many items, items can have descriptions in many languages so you would need to create a one to many relationships.
  5. an example of many to many relationships is an order with many items that have many variants of each item such as different colour paints in different quantities.
  6. the items_orders creates many to many relationships between orders and item ids.
1 Like
  • One to One
  • One to Many, Many to One
  • Many to Many
  • Self Referencing
  1. When there is unique data for one entry e.g A customer can only be associated with one Social Security number.

  2. Foreign Keys are used for all kinds of database relationships. It is used to ensure referential integrity of the data.

  3. For when one client on a stock exchange purchases multiple different stocks.

  4. When determining the classes that a specific cohort of university student are taking.

  5. The items_orders table resolves the many to many relationship between orders and items.

1 Like
  1. One to one, one to many and many to one relationships, many to many relationships, self reflecting relationships, and represent in a database.
  2. A real life example of One to One relationship is when a person has a library card and your name and adress belongs to same person, but has diferent book items that they have checked out.
  3. A. Because it refers to a matching record between customer id and customer table, witch is called Foreign Key, it is used for all database relationships.
    B. Using Foreigh key witch can be indexed to see all connections of customers and adresses.
  4. A crypto exchange can have many customer id’s with different adress id’s same order id, amounts, coins and different date or just one customer id with same adress id and date.
  5. Facebook could be used to see friends of friends as use case scenerio for many to many.
  6. Items to order purpose is to create Many to Many relationships between items and orders.
1 Like
  1. Types of relationships that can be stored: 1:1 relationships, 1:Many and Many:1, Many:Many and Self Referencing Relationships.

  2. An example in the real world might be a customer name and address.

  3. The customer_ID is a primary key in the customers table. It can be used to identify a specific customer. Also, a primary key in another table can be used as foreign in order to reference a relational row in another table.

  4. A single customer who makes multiple or repeat orders of an item or items. On the items table the 1:M/M:1 relationship may be reversed.

  5. A many:many relationship is likely to exist between orders and items. Commonly existing in say something like a supply chain.

  6. It simply stores the IDs of both the items and orders, meaning it doesn’t have to store the rest of the data of each item or the order.

1 Like
  1. The different kinds of relationships we can represent in a database are.

    • One to One Relationships
    • One to Many and Many to One Relationships
    • One to Many and Many to One Relationships
    • Many to Many Relationships
    • Self Referencing Relationships
  2. we use a one-to-one relationship when one table can only have one relationship with another table.
    I.E a person and their account number.

  3. In the article. In the one-to-one section, the column called customer_id in the customer’s table is called a “Foreign Key” and is used to reference a column in another table.

  4. A real-world example of “Many to One/One to Many” relationship would be a company and its employees while each employee would go to one company, one company would have many employees.

  5. A real world example of a “Many to Many” relationship would be a class with many students and a student having many classes.

  6. The Items_Orders table serves as a bridge between two “one to Many” tables and encompasses all the date within those tables.

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

  2. If only one input can have a relationship to only one other input.

  3. Because it insures that the customer will have a unique ID allowing for a relationship to occur between the Customer and Address table. Resulting in only one unique address to be associated with one customer.

  4. It can be used when you for example, want to track the different purchases a specific credit card does at your vending machine. (Many to One)

  5. It can be used when students attend a school and they attend several classes within that school.

  6. It Creates 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
    - One-to-Many / Many-to-One
    - Many-to-Many

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

    • In most countries the Law stipulates that Marriage is a contract between one person and exactly one other person :wink:
  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?

    • I guess the question actually concerns the “address_id”. It is used as a Foreign Key to the ADDRESSES table in order to identify “address_id” from it and associate it with the given customer. The “customer_id” just identifies every single customer and is not very interesting by itself.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.

    • I (one) own multiple (Many) pairs of shoes :wink:
  5. Give an example from the real world when would need to use a “Many to Many” relationship.

    • Children (when there are more than one in a family), parents.
  6. What does items_orders table do?

    • It models a Many-to-Many relation.
1 Like