SQL Relationships - Reading Assignment

  1. What kinds of relationships can we represent in a database?
    There are four relationships: One to One, One to Many and Many to One, Many to Many, and Self Referencing.

  2. When do we use “One to One” relationships? Give an example from the real world.
    When one entry can be linked to only another entry. Name and Address is an example.

  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 give two tables a point to link to each other. Connected by a Foreign Key.

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

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    At a college, Student to Classes.

  6. What does items_orders table do?
    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-reflecting.
  2. A user and their address. A case file number and it’s user.
  3. This is called a foriegn key and it is used different types of databases relationships. It’s purpose is to show referential integrity of the data
  4. Creating a system like sis which is a soft where for universities. In the application a student may have one course, but that course many have many students.
  5. A person can go to different McDonald’s, and a signal McDonald’s can host/serve many different people.
  6. It is used to create a many relationship between the items and orders.
1 Like
  1. In a database, the represented relationships are, “One to One”, “Many to One/One to Many”, “Many to Many” and “Self Referencing”.

  2. “One to One” relationships are used when an address can belong to only one customer. A drivers license is issued to one person. He/she is the only one with that unique identification number.

  3. The customer_id in the table is used to simplify retrieval of information, by the use of identifiers. This column is assigned a placement with a specific identifier which can be easily retrieved by calling a specific customer_id which references other placements in that row.

  4. You would need to use a “Many to One/One to Many” relationship in an enterprise setting, where an employer has many employees.

  5. Books and authors are a real world example of a “Many to Many” relationship. An author can create many books, and a book can be written by multiple authors.

  6. An items-order table creates a “Many to Many” relationship between the items and the orders. Each order can contain multiple items, and each item can also be in multiple 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 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. The citizen number is fairly unique to an individual

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. 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 there is only one corresponding entity.

An example would be an email. Each email corresponds to only one person.
email address => person

  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 Foreign Key representing a unique id for each customer. It can be used in a relationship with another table or id to define the relationship between each unique customer and another table or id.

  2. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    {tournaments} <=> person <=> {tennis players}

  3. Give an example from the real world when would need to use a “Many to Many” relationship.
    A person / member can belong to many clubs and clubs can have many members.

{clubs} <=> {members}

  1. What does items_orders table do?
    It represents the “Many to Many” relationship between Items and Orders. “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

Response:

  1. Databases can represent the following types of relationships: One to One, One to Many/Many to One, and Many to Many.

  2. A type of 1-to-1 relationship we use is when we $CashApp a payment to someone on our list.

  3. The customer_id column helps to condense the information of the customer into solely numeric form. The database will then recall the name of the customer that matches the id when needed, but does so in order to process information quicker.

  4. Our order history from Amazon is an example of “One to Many.” We are the “one” who have “many” orders connected to our account and vice versa.

  5. Not entirely sure, but I think the app store, whether it’s iOS or Android, is an example of “Many to Many.”

  6. The items_orders table will show the relationship between items and orders (many to many).

1 Like

One to one
One to many and many to one
many to many
self referencing

Our phone number or telegram ID

This is called the foreign key, its actually giving a specific ID to a specific customer and making relation between the 2 columns.

One person having few different bank accounts

whatsapp groups

It creates many to many relationships

1 Like

Following your Amazon example: “many” items are connected to “many” account orders.

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

Carlos Z.

@thecil
Thanks for helping me understand that better :raised_hands:

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.
    We use one to one relationship when the relationship is unique to one entry or row or tuple. An example is the relationship between e-commerce user name and registered email address used for login.
  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 reason for the author to use customer_id is to store the one-to-one relationship with the customer_name, basically it works as the tuple / row. The address_id is created to separate the table based on the data type (customer name vs street address, two different thing). To connect customers to address the address_id can be used as foreign key.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Relationship between someone’s name and the registered cars this person has.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Children - parents relationship
  6. What does items_orders table do?
    items_orders table can creatte the many to many relationship between the items and the orders.
1 Like
  1. one-to-one, one-to-many, many-to-many, self referencing.
  2. describing username entity, example - identity card of a student.
  3. customer id is a foreign key that connect to customers addresses. it is used in order to identify the customers.
    4)Many to one/one to many relationships - example, each customer have many orders, a customer orders many products.
    Ex, many to one … John, Mary and Ivan ordered the same products.
    Ex, one to many …George placed an order of different products.
  4. many to many … tags represents to different products and products can have many tags.
    Ex, sports and ball
  5. Order table do… to keep track of all customers id and orders list references.
1 Like
  1. Relationships define connections between data points, and as such we can represent most real-world relationships. Some relationships are one to one, one to many, many to many, etc.
  2. A real-world example of a one-to-one relationship can be the driver’s license of an individual.
  3. Foreign keys are unique identifiers from another table that has more fields to specify that value.
  4. In general, functions are relationships that must be one-to-one or many-to-one relationships. For example, the hash function is a many-to-one relationship in which more than one input can have the same output.
  5. Many-to-many relationships can be between assets and their owners. For example, two people can jointly own more than one car.
  6. Item_orders has the relationship between orders and items.
1 Like
  1. One to one relationship, One to Many and Many to one relationships, Many to Many relationships, Self Referencing Relationships

  2. It is when an information is only belong to one entity like Name and ID number or Name and Cellphone Number, or IP address etc

  3. The customer_id is the unique numbers given so that overlapping wont happen , it is automatically connected since it is at the same row, meaning both customer_name and customer_address are owned by certain customer_id

  4. When we do online shopping, we can order product A, B and C. (One to Many). Dairy Farm, Machine supplier send their goods to a Milk Factory (Many to One)

  5. Many to many example: I bought Fried Chicken and French Fries while he bought Hamburger, French Fries and Soda

  6. Items_orders table purpose is to create Many to Many relationship between the items and the orders

1 Like
  1. In an SQL database, we can represent: One to One Relationships, One to Many/Many to One Relationships, Many to Many Relationships, and Self Referencing Relationships
  2. we can represent user to user profile
  3. it is faster and less taxing to connect a short integer(like customer ID) to another short integer (like address ID) and reference them in separate tables
  4. when a user owns many different coins in one wallet, that one user can be connected to the many coins he owns
  5. you can connect the user ID to the many order IDs to their product IDs
  6. creates many-to-many relationships between the customers, orders, and products.
1 Like
  1. One to One Relationships
    One to Many and Many to One Relationships
    Many to Many Relationships
    Self Referencing Relationship

  2. One entry on database can be linked with 1 item in a column.Example 1person/ 1 id

  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 relationships. The foreign key identifies a column or group of columns in one table that refers to a column or group of columns in another table.

  4. Online Sport clothes shop: Diferent constumers can make one or multiple orders, but an order belong to one costumer.

  5. Buy online books on e-bay, amazon. Big online marketplace for multiple orders and items.

6)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. What kinds of relationships can we represent in a database?
    one to one, one to many, many to one, many to many and self referencing reletionships are the ones covered in this article.
  2. When do we use “One to One” relationships? Give an example from the real world.
    For example we could have a partner list -understanding that most of the people will only have one partner at a time, or could be a husband or wife relationship-
  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?
    This customer Id is called foreign key and it is used for all kinds of database relationships (which I still dont know too much about)
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    an example of this could be a parent/son relationship. one parent can have several children, while every child can only have 2 parents (more if they are part of a mutual adoption club, but this is another issue)
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    One example could be orders in a restaurant, where you have different tables, each table with several orders (when the customer changes, it will have a new order) and each order can have several items from the menu. An extra difficulty would be that each item of the menu which is ordered in any order, could update the inventory, because each item of the menu should decrease an amount of ingredients, which could in turn trigger new orders from the suppliers and so on and so forth.
  6. What does items_orders table do?
    I didnt understand this one … mainly beacuse the graph on the article is not related to the tables in the article… It looks like the only purpose is to link an order ID to each item that the order contains, do we really need a new table for that? It seems we do… but wouldt it be better if we also put some quantities of the items? or some options like colour or something…

What kinds of relationships can we represent in a database?
Answer:

  • 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.
Answer: When one record is inextricably linked to another record. Example: Social Security Number and my Name.

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?
Answer: It’s used in this way as a one to one mapping because customer can only have one customer ID in this example. It’s used as a “Foreign Key” in a separate table and mapped to that customer name and address ID.

Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
Answer: One customer makes many orders. Or one order can have many items.

Give an example from the real world when would need to use a “Many to Many” relationship.
Answer: A many to many relationship model is useful in the case of students taking many different subjects in school. In real life, each student will take many subjects, and each subject will be studied by many students at the same time.

What does items_orders table do?
Answer: items_orders table creates a “Many to Many” relationship between the items and the orders.

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.
If a field/ column has a relation to only one other column or field. A user and its 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 customer id relates to the customer table where the customer id is a primary key and shows the record of items about that customer. It connects by what is called a Foreign Key.

Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
My phone contains many phonenumbers and many people have my number.

What does items_orders table do?
The only purpose is to create a Many to Many relationship between the items and the orders.

1 Like
  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 accounts can be attributed to one customer
  3. There can be multiple variants of the same species of animal, like a shark. A shark is one of many types of fish.
  4. It is used to create “Many to Many” relationships between the items and the orders.
1 Like

For some reason my last two answers have not been included. Can anyone see them?