SQL Relationships - Reading Assignment

  1. In databases we can represent many types of relationships like; One to One Relationships, One to Many and Many to One Relationships, Many to Many Relationships and Self Referencing Relationships.
  2. A one to one relationship is used when a specific value can only have relation to one other element.
  3. Each customer has a unique customer_id which is also associated with a unique address_id that is linked to the customers actual address in the address table.
  4. A real world example of a many to one would be how many kids may have the same birth mother but every kid only has one birth mother.
  5. A real world example of a many to many relationship would be how each person can order multiple things and how eachthing can be ordered by multiple people.
  6. items_orders table represents what items were in which orders.
1 Like
  1. What kinds of relationships can we represent in a database?
    We can represent One to One-, One to Many- or Many to One- and Many to Many relationships.
  2. When do we use “One to One” relationships? Give an example from the real world.
    A user and his fingerprint.
  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?
    Instead of having the address in the same table we create a new table with the different adresses and every customers ID is pointing to the corresponding address in the second table.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Paycheck history of an employee.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    One man can use the public transport but the public transport is used by a lot of people.
  6. What does items_orders table do?
    Create a many to many relationship.
2 Likes
  1. One to one, one to many, many to many, self-referencing
  2. A user and his passport id
  3. Customers are identified via their id numbers and each number points to an address that is represented in a separate table.
  4. One Internet service provider can be used by multiple clients
  5. One ingredient can be used in many recipes, but also one recipe may require many ingredients.
  6. It creates a many to many relationship.
2 Likes
  1. One to One relationships, One to Many and many to one relationships, many to many relationships, self referencing relationships
  2. You would use one to one relationships when there is only one relationship between the tables. Like a list of phone numbers corresponding to the owner of the phone number.
  3. The customer_id column is what gives the relationship between the tables.
  4. When you order from your amazon account, all your orders are logged to you.
  5. When you link say orders to items in stock
  6. the items_orders table contains the information that links the orders and items tables
1 Like
  1. What kinds of relationships can we represent in a database?
    You can represent one to one, one to many or many to many relationships.

  2. When do we use “One to One” relationships? Give an example from the real world.
    Imagine that you work in the National Register Office. Each citizen may have up to one driver’s license. This driver’s license usually has a unique identifier, so, each time a license is created, this identifier will be bound to a specific citizen.
    So, this is a good example of a one to one relationship, because each driver’s license identifier that exist will be assigned to an unique citizen, however, those citizens may, or may not have a license, but in case they have, they will only have 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?
    Customer_id is a primary key in the Customers table. It allows to identify a particular row of a table, because it is unique. It is used to create a relationship between a customer and its address.
    Say, if you add this Customer_id as a Column (called foreign key) in the Addresses table, it will allow you to identify the specific customer from the Customers table that is bound to the address.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    In Facebook, you have Users and Posts. The “publish” relationship allow users to publish as many posts as they want, however, each post may be published by only one user.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    In a music streaming platform you will have Songs and Users. The “like” relationship will allow you to know which users enjoy which songs. Each user may like as much songs as he or she wants, and each song may be liked by as much users as it can.

  6. What does items_orders table do?
    It is an intermediary table, which is required to store many to many relationships.

1 Like
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. When a value has 1 other value, any ID card.

  2. Foreign key, it’s used to point to data.

  3. Tshirts with different colors.

  4. in a multi value systeme.

  5. Only many to many.

1 Like
  • What kinds of relationships can we represent in a database?
    -> 1 to n / 1 to 1 / n to n

  • When do we use “One to One” relationships? Give an example from the real world.
    -> the ID number on your ID card. 1 card with this ID is link to 1 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?
    -> here can be more than one customer with the same name that might be differentiated by different addresses. Using customer identifiers and address identifiers helps to differentiate customers and addresses.

  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    -> All the country in the world where I traveled.

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    -> All the country in the world where everybody traveled.

  • What does items_orders table do?
    -> The items_orders table links the item IDs from the items table to the order IDs from the orders table to list all the items in an order.

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.
Small data base with a low number of customers and items, small mechanics shop or a small cleaning business.

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 linked to the address_id for referencing.

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.

Give an example from the real world when would need to use a “Many to Many” relationship.
Situations where you have muliti order/items/customers/couriers/locations

What does items_orders table do?
It connects the item to the customer

1 Like
  1. One to one, one to many, many to many and self referencing relationships.
  2. We use one to one relationships when customers are referencing their addresses
  3. The customer id is a reference point to the customer name and we connect it to the address id and vice versa connecting the customer id to the address name.
  4. A person can buy many books can those books can be written inn multiple languages. Each order of books can only belong to one customer.
  5. When ordering groceries from the store, many people can buy many types of items for example: bananas
  6. They create many to many relationships between items and orders.
1 Like

1.) In Databases we can represent one to one, one to many, many to many and self referencing relations.

2.) One to one relations are the simplest way of relations in Databases and it means a connection between only two depending data structures. So for example the Index at the beginning of a book only refers to one chapter in the book itself.

3.) The customer ID in the table in the given example makes sure that only one customer has one defined address ID. If you only use the name of a customer, it will causes directly an error, if two customers come with the same name.

4.) One to many or vice versa in real life is, for example like the relation between a person and the clothes in theirs wardrobe. All clothes belong to that one person and the person can decide what shirt to wear and also which trousers to wear at the same time with the shirt and so on. Otherwise all shirts and trousers only usually belongs to one person.

5.) The many to many example from the real world could also be the example given in answer 4.). In this case you might have a table full of shirts, a table full of trousers, another full of socks and so on.
Each shirt can be connected to every trousers and as well to every pair of socks. And so on.

6.) Items_tables has the purpose to create many to many relations by connecting tables together.

1 Like
  1. What kinds of relationships can we represent in a database?
    one to one: one to many; many to many; many to one; and self referencing
  2. When do we use “One to One” relationships? Give an example from the real world.
    when we need one user to math with only one other variable
  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 he can connect each unique customer to their unique address. he does so by using a foreign key that matches the customer to their address.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    when customers can make multiple orders or orders can have multiple items like in an e-commerce business
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    when a customer can oder multiple items and an item can be in multiple orders
  6. What does items_orders table do?
    it creates a many to many relationship between the items and orders
1 Like

1,2,4,5 - What kinds of relationships can we represent in a database?

One to one relationships: one record in a table is affiliated with one and only one record in another table.
Example: Customer Name and Customer ID

One to many relationships: One record in a table can be affiliated with one or more records in another table Example: States, because multiple customers can live in the same state.

Many to many relationships: multiple records can be affiliated with other multiple records. Example: Multiple products can be purchased by multiple different customers.

Self reference relationships - this is the part where my brain fried. I’ll need to research more.

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?
Programmers seek to optimize the amount a information in a database. By giving customers a “customer ID”, it creates an integer that represents the data of the customer. This number can be efficiently connected to other tables that are affiliated with the addresses in that database.

6 - What does items_orders table do?
It establishes the relationship between the table of items and the table of orders, an example of a many-to-many relationship.

1 Like
  1. One to One, One to Many and Many to One, Many to Many and self referencing.

  2. If each address can belong to only one customer, this is a One to One. In the real world, the driver’s licence is an example.

  3. That refers to the matching record in the Address table. This is called a “Foreign Key” and it is used for all kinds of database relationship.

  4. Costco online shopping, I can make multiple orders, order can have several items and we’ve a description of each items.

  5. 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. As an example, buying a car with an online dealership.

  6. The Items_Orders has only one purpose, and that is to create a “Many to Many” relationship between the items and the orders.

1 Like
  1. Relationships: one to one, one to many, many to many
  2. Name and address
  3. Customer_id is a variable that can reference the same variable to another table
  4. Many to one is like one person but many pets
  5. Items_orders is the variable to cross-reference the many orders to another table
1 Like

1- a)One to one.
b) One to many.
c) Many to many.
d) Self referencing.

2- When a field like an id belongs only to one person.

3- It is called a foreign key.It is used to have a relationship between the tables.

4- People having a portfolio of stocks.

5- Peobple buying stocks, different dates, exchanges.

1 Like

-one to one
-many to one/one to many
-many to many
-self referecing
2. When we have field like an id belongs to only one person. In Romania we have the unique identity cards with unique identity code on them, so one uinique code belongs to one person
3. It is used as a freign key refering to another table, its used as a relationship key
4. Each customer may have zero, one or multiple orders. But an order can belong to only one customer.
5. A series of items can contain many orders.
6. it has only one purpose, and that is to create a many to many relationship btw the items and the orders

1 Like

Reading Assignment: SQL Relationships

  • What kind of relationships can we represent in a database?
    • One to One Relationship
    • One to Many Relationship
    • Many to Many Relationship
    • Self-Referencing Relationship
  • What do we use “One to One Relationships?
    • For example, in a student database, each student will have 1 unique student number only assigned to them in the database. Each student number will only be linked to a single student in the whole database.
  • In this article in the “One to One”-section, the author of the article has a column called customer_id in the customer table. Why? How is it used to connect customers to addresses?
    • The customer_id is the unique identification number for each customer and each address is linked to the customer_id, connecting the address with the correct customer.
  • Give an example need to use a Many to One / One to Many Relationship
    • A customer may have many orders, but a specific order can only belong to one customer.
  • Give an example when would need to use Many to Many Relationship?
    • For example, if a student registers for many classes and a class includes many students.
  • What does items_orders table do?
    • Creates a Many to Many Relationship between the items and the orders.
1 Like
  1. One-to-one, one-to-many, many-to-many, cross referencing
  2. One person has one nose
  3. The customer_id column is used to identify a record (customer) so then any attribute of that record can be retrieved if the customer_id is known. This helps establish the relationship between tables that have the customer_id column.
  4. One mother can have more children
  5. Multiple rental cars are driven by multiple people
  6. It stores many-to-many relationships between items and orders
1 Like
  1. What kinds of relationships can we represent in a database?
  • One to one;
  • One to many or many to one;
  • Many to many;
  • Self referencing (relations within the same table).
  1. When do we use “One to One” relationships? Give an example from the real world.
  • Passport number and personal ID number. One person has one passport within a country.
  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?
  • In that example, every customer has an ID and also every address has its own ID. Then in the customer section an address is assigned to a customer.
  • In one-to-tone context this could be useful maybe not for customers, but for example workers that are rotating between different facilities, or drivers that are swapping cars. The car doesn’t change, the driver doesn’t change, but the relations do change.
  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
  • All kinds of government databases. One person can have several properties, vehicles, jobs…
  1. Give an example from the real world when would need to use a “Many to Many” relationship.
  • Banking system. Many accounts making many transactions. And each transaction is what makes it possible - one sender, one recipient.
  1. What does items_orders table do?
  • It links an order with every item that is in the order.
  • Another way would be a separate table for each order, probably less efficient.
1 Like
  1. What kinds of relationships can we represent in a database? 1to 1; 1 to many, many to 1, many to many and self referencing.

  2. When do we use “One to One” relationships? Give an example from the real world.
    For example in a company in human resources; an employee table would give us how many years an employee has been with the company. The # of years would be a column

  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 an attribute of the customer used to identify the customer and used as a foreign key that could bring information from another table.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many to one: for example how many people belong to a single group in FB.
    One to many: How many groups does one person belong to in FB.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    When determining how many customers ordered what products.

  6. What does items_orders table do?
    Create a many to many relationship.

2 Likes