SQL Relationships - Reading Assignment

  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 relationships

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

This is used for simple relationships for example the address of a specific grocery store.

  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?

This is a foreign key. It is used as a reference id to retrieve the customer id data and provides the possibility to connect customers to addresses

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

For example to index the grocery basket of a customer

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

For example indexing taxi rides from several clients for many different taxi drivers.

  1. What does items_orders table do?

It shows the ID of an ordered item in connection to the ID of an order of a customer

1 Like

Excellent answer sir! really well documented! keep it like that please! :muscle:

Carlos Z.

Excellent answer sir! really well documented! keep it like that please! :muscle:

Carlos Z.

  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.
    Each customer account for a mobile operator, for example has one identifier linked to its name.

  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 concept of foreign key is used to to create database relationships. In the example, “address_id” is the attribute in one table marching the record in the other table.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Once customer can have multiple billing account (One-Many). Many subscriptions can be linked to one billing account. (Many to One)

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    Many customers can have multiple services and these services can serve multiple customers.

  5. What does items_orders table do?
    It 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.
    ID and finger print. ( injective functions)

  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?
    It is used as a reference id to retrieve the customer id data and provides the possibility to connect customers to addresses

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A person can have many different cloths. (invers surjective functions)
    Cloths can contain many different fabrics. (surjective functions)

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    A person can have many houses, and the houses can contain many people. (surjective functions combined with invers surjective functions)

  5. What does items_orders table do?
    It shows the connection of the order id to the item id

1 Like

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

If each address can belong to only one customer,
this relationship is “One to One”. This kind of relationship is not very common.

It saves space to substitute the customer name by customer id.
It a primary key in the customer table, but a foreign key in the orders table
because it referencers to the customers table.

Many to One: many customers want product_xy
One to many: city_xy and its inhabitants

many tables in restaurant with various orders

lists each ordered item (many) to its order_id (many), relationship between orders and items.

1 Like

1)one to one
one to many / many to one
many to many
self reflecting relationships
2) example of one to one: DNA, fingerprint, face recognition these are all unique characters belonging to one person
3) its a foreign key in the customers table, it relates to the customer
4)paying salaries : one person pays salaries of many people in a company
5) there are many airplanes with many destinations and many people
6) to create a many to many relationship between the 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 and self referencing

  2. When do we use “One to One” relationships? Give an example from the real world.
    When one unique attribute has a relationship with one other unique attribute E.g. a person and their 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?
    The customer_id is used as a reference code for a particular customer which is referenced in the address table so that customers can be matched with their addresses.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Someone can have many crypto wallet addresses but each wallet address can only belong to one person (ignore multi-sig!)

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Someone can order many items, and those items can be ordered many times

  6. What does items_orders table do?
    Combines the Order_id which gives information about the customer and the Items_id which gives information about the items ordered to determine which items the customer ordered.

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, self referencing

  2. When do we use “One to One” relationships? Give an example from the real world.
    When one piece of data belongs exclusively to another piece of data. An example might be a person and their social security 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?
    This is way to create efficiency within the database by utilizing a foreign key. In other tables, you can now use the customer ID to reference who the customer is, rather than having to import a long string of names.

The same concept is used to identify addresses. Rather then import a lengthy address to a new table, such as the order table, you can quickly reference address information using an “address id” in lieu of the actual address.

  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    If you wanted to identify how many customers lived in a particular state.

  2. Give an example from the real world when would need to use a “Many to Many” relationship.
    Netflix may want to see the relationship of multiple customers and the similar movies and/or documentaries they viewed in the past.

  3. What does items_orders table do?
    create a many-to-many relationship between items and orders. The order ID summarizes who ordered, while the item id tell us what was ordered.

1 Like
  1. One to One Relationships; One to Many and Many to One Relationships; Many to Many Relationships; Self Referencing Relationships
  2. Name and address (one name has one address)
  3. It is a unique number to be used in other tables to get the relation in the other table.
  4. A father can have more children or a child can have more grand parents.
  5. Create a many to many relationship between items and orders.
2 Likes
  1. One to one, one to many, many to one, many to many
  2. A list of Social Security Numbers which corresponds to a list of person who have those numbers.
  3. The customer_id is a foreign key using to connect the person to the address by pointing certain customer record to certain address record.
  4. From example, each order can contain multiple items and each item can also be in multiple orders.
  5. Use to create many to many relationship between items and orders.
1 Like
  1. one to one, one to many, many to many and self referencing
  2. A customer ID and email address, a real world example would be one customer can only have one email address.
  3. It is being used as a foreign key which is used to establish a relationship between tables but is not the primary relationship.
  4. A global website that supports many different languages and items for a wide customer base, for example ecommerce sites usings shopify would be a real world example.
  5. Class schedules for all students on a college campus.
  6. Creates a many to many relationship
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
    Self Referencing
  2. When do we use “One to One” relationships? Give an example from the real world.
    My name and my phone 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?
    The customer_id column identifies the customer who has a relationship with the address_id.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Orders can contain many items from one customer.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    An online store having multiple orders from multiple customers.
  6. What does items_orders table do?
    It creates a many to many relationship between orders and items.
1 Like
    • One to One Relationships
    • One to Many and Many to One Relationships
    • Many to Many Relationships
    • Self Referencing Relationships
  1. Like a costumer and his adress = Ex : Paul Newman--------- 3276 Lakeshore, San Francisco
    Jack Johnson --------- 12225 Madisson BLVD, Los Angeles
    Where each costumer have a unique adresse paired with it’s unique Name

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

  3. Like a pizza restaurant One single costumer can order different type, size, flavor of pizza and also place order for Pick-up or Delivery. One costumer will need a quantity of relation to make everything accurate.

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

  5. 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 (vice versa), many to many, and self referencing.

  2. When do we use “One to One” relationships? Give an example from the real world.
    When an entry can only belong to another single entry. Our Social Insurance Numbers, which we use in Canada. Each number is unique to each person so there can only be one record per 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?
    It is a unique foreign key value that creates a relationship between the customers table and the addresses table.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Taking my car in to the dealership for service. A relationship between customer and the dealership with services is created.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Again with the car/dealership example. Many cars require many parts that also require clients and technicians to be a part of a many to many relationship database.

  6. What does items_orders table do?
    To create a many to many relationship between items and orders tables.

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.
    When an entry can belong to only one subject. Ex. Individuals and their phone numbers.

  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 foreign key and references the customer table. There the customer_id is a primary key and show the record of attributes of a specific customer.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many-to-one/one-to-many is used in e-commerce where one user can have many orders.
    Also, within these orders there may be many items, which is another example of this relationship.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    This is when there needs to be multiple instances on both sides of the relationship. An example would be a restaurant serving many customers on many orders that contain many items.

  6. What does items_orders table do?
    This table creates a many-to-many relationship between items and the orders.

1 Like
    • One to One Relationships
    • One to Many and Many to One Relationships
    • Many to Many Relationships
    • Self Referencing Relationships
  1. The relationship between me and my toothbrush, it can only belong to me.
  2. It is called foreign key and it is used for all kinds of database relationships.
  3. I can have a wallet with many or zero bitcoin and those bitcoins in my wallet can belong only to me.
  4. I can buy a dress from a website and other girls can buy the same model of dress.
  5. 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. The various relationships are one-to-one, one-to-many, many-to-many or self-referencing relationships
    2.One-to-One relationships are used when certain values in one table are automatically matched to a certain value in another table, creating a relationship that never changes. i.e. in customer data, a mobile phone number would invariably be linked to one person. It would be a one-to-one relationship
  2. the customers_id is an autonumber, i.e. it generates a new number for every individual record. At that same time it is the primary key and reference for that customer to be used in other tables
  3. an example of one-to-many is the national identity register… the unique national registration number is used for many purposes but and tied to a lot of databases and tables, but at the same time is unique to one person, hence the “one”
  4. A typical example of many-to-many relationships would be the friends profiles in facebook. One person can be friends with many people, but at the same time each of those people can also have many friends, one of which was the original person.
  5. the items_orders table makes that each customer can have multiple orders, resulting in a many-to-many relationship. this additional table makes this possible.
1 Like
  1. 1-to-1 rel, 1-to-many & many-to-1 rel, many-to-many rel, relf- referencing rel
  2. when one key= value -> name and social security
  3. this is done to create a rel between customer & the address
  4. order history reccord of a customer
    5)list of pupils who attend school is requiered
  5. create many-to-many rel between items & orders
1 Like
  1.   One to One Relationships
       One to Many and Many to One Relationships                                            
       Many to Many Relationships                                                                          
       Self Referencing Relationships
    
  2. If one information can belong only to one person like your retina structure

  3. The customer_id column identifies the customer who has a relationship with the address_id

  4. My orders in a restaurant and all residents of my home town

  5. When customer order several items and every item can be can also in different orders we have a „many to many“ relationship

  6. This table creates the „many to many“ relationship between items and orders

1 Like