SQL Relationships - Reading Assignment


#41
  1. What kinds of relationships can we represent in a database?
  • one to one rel.
  • one to many and many to one rel.
  • many to many rel.
  • self referencin rel.
  1. When do we use “One to One” relationships? Give an example from the real world.
    when there can be only an attribute can only be matched to exactly one other attribute.
    lets say in table 1 you have the e-mail Address and password of a user. and in table 2 you have the usernames. each username can only be link to one email and to one password. each email can only be related to one username.

  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?
    Each customer id gets one adress Id. this foreign key is then used to find the address. To do so you would enter the customer id, from that you derive the address Id and from there you get the address from the address table.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    When the children are related to a father. there can by two children, none, or one child be related to one father. Probably you would use a many to many because the children are also related to a mother.
    another example could be picture to profile pictures on FB. Because you can have many profile pictures.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    children to parents. each child has two parents, and each parent can have 0, 1, 2, etc. children

  5. What does items_orders table do?
    It links items to the orders


#42
  1. What kinds of relationships can we represent in a database?

Ans :

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

Ans : It refers to relationships of two items in which one can only belong with the other. They are a pair.

Example : Santa Claus is associated with one holiday.

  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?

Ans : This is done for storing a relationship between the customer and the address. Foreign key is used in order 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.

Ans : One to many/Many to one : if you have a list of works of art and a list of museums, each work of art can only be in one museum at a time, but each museum can have many works of art.

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

Ans : Many to many : if you have a list of books, and a list of authors , each book may have one or more authors, and each author may have written multiple books.

  1. What does items_orders table do?

Ans : items_orders is representing a many-to-many relationship. The Items_Orders table is working as Junction between those two tables so this table is also known as junction table .


#43
  1. What kinds of relationships can we represent in a database?

One to One.
One to Many.
Many to Many.

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

For example, it could be used to store the user’s social security number and some other unique information. Such info can be stored apart from his name or user id to meet the security regulations like GDPR.

  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?

This is a primary key to uniquely identify the customer records. It is used to reference the “customer” records by other tables. It is also used to build an index.

How is it used in order to connect customers to addresses?**

Another table references the “customer_id” primary key and hence can access the exact “customer” record it points to. JOIN operators of the SQL language can be used for this purpose.

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

A list of purchases in the online shop. Each purchase record contains a list of goods with amount and prices (this can be normalized further but I guess it’s out of scope of this quiz).

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

Basically, it is a graph. A few good examples are :

  1. Friends in a social network
  2. A subway map (or a railway map)
  1. What does items_orders table do?

It is specific to the article’s database. It holds the price, amount and a foreign key to the goods table. The high level goal is to make the goods fungible despite being different. The low level goal is to have the DB schema normalized while ensuring the required logic and relations between goods and purchases.


#44
  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.
    One to One relationships are useful for entries that have an exclusive identifier. Results can only have a relationship with a sole user. An example is the use of a Social Security number uniquely identifying an individual person.

  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 column states an exclusive match with a unique address_id. This solidifies a relationship between the two entries. Using this will ensure a 1:1 relationship.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A real world example of “Many to One/One to Many” relationship is obtaining a list of home addresses on a street

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    One sales team’s performance scores against another from another office.

  5. What does items_orders table do?
    Creates a link between customers and unique item_orders to clarify exactly which customer bought what item.


#45
  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.
    Listing of the owners of apartments in a building.
  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?
    Each customer has an ID assigned so that the names do not have to be duplicated in the address table for example. Instead, the ID represents the customer in the address table.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    One person can own multiple apartments and one apartment can be owned by multiple people.
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    You would use ‘many to many’ to find out if any of the apartment owners in the building owns more than one apartment. And are there any multi-owned apartments owned by the same people, for example.
  5. What does items_orders table do?
    It creates ‘many to many’ relationships between the orders and items.

#46

1
1to1, 1 to many, many to many, self-referencing.
2
User-access table and application access log table. We use the username in table 1 and their matching email in table 2.
3
customer_id is a unique anchor piece of data a foreign key connecting the customers data to their matching address data, linking the attributes.
4
One to many could be for example 1 user who ordered many times in the same eshop, many are their orders/e.g. order numbers. Many to one could be many orders but of the same one item.
5
Many to many could be used for the same above but when orders contain multiple items.
6
items_orders table is created as another table establishing the relationship of the orders to items in the above scenario.


#47

1.What kinds of relationships can we represent in a database? A: 1 to 1, 1 to Many, Many to 1, Many 2 Many

2.When do we use “One to One” relationships? Give an example from the real world. A: Monoganic relationship, spouse.

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? A: customer_id is used in customer_order table; the customer_id is not used there, but you mean instead address_id is used as the foreignkey.

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

5.Give an example from the real world when would need to use a “Many to Many” relationship. A: Inheritance: siblings to Parents, Parents to Childs.

6.What does items_orders table do? A: “Many to Many” relationship


#48

I guess self-referencing is just “BS” because any self-ref-relation can be achived using only any of the other types 121, 12M, M21, M2M.


#49
  1. Relationships represented are; one to one, one to many, many to one, many to many.
  2. I’m going to take a chance and say; a peer-to-peer single transaction on the blockchain.
  3. Since addresses change- even shipping addresses, such as when a birthday gift is sent- this can be used as a differentiator. I’ll expand upon this in number 5.
  4. For this I will stick to the birthday gift theme; the customer is ordering three basic birthday items to send to the recipient at another address. Those three items are frequently purchased by many customers, and, are in many orders.
  5. In the progression of #'s 3 & 4; we have many customers, with many orders, with many items, with many addresses. These often overlap. For example, Amazon. This can become extremely intricate, in that, multiple values can be attached to each piece of information; customers, orders, items, addresses. To ensure correct, efficient delivery, many to many would be used.
  6. “Items_Orders” ensures the proper matching of all variables as I described in #5

#50
  1. One to One, One to many or many to one, many to many and self-referencing relationships
  2. An example of a one to one relationship would be one customer has one address.
  3. The customer_id combines the (name/address) fields for easier reference. It serves as a foreign key that can be referenced by all other aspects of the database.
  4. customers and orders could be a many to one and one to many example. One customer could have many orders, but each order only belongs to one customer.
  5. customers and items can be an example of many to many. Any customer can buy any amount of items, and each item can be purchased by any customer.
  6. the items_orders table creates a many to many relationship between items and orders.

#51
  1. What kinds of relationships can we represent in a database? One to One Relationships - not used often. Can usually be in the same table. One to Many and Many to One Relationships - most common type. Many to Many Relationships Self-Referencing Relationships

  2. When do we use "One to One" relationships? Give an example from the real world. - not used that often, could probably have the information in the same table.

  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 the primary key in the ‘Customers’ table and the address_id would be the Foreign Key

  4. Give an example from the real world when would need to use a "Many to One/One to Many" relationship. - an e-commerce business has Customers and they can make multiple orders.

  5. Give an example from the real world when would need to use a "Many to Many" relationship. - when you need multiple instances on both side of the relationship. For example, each order can contain multiple items and each item can also be in multiple orders.

  6. What does items_orders table do? - it has one purpose and that is to create a "Many to Many" relationship between, for example, items and orders.


#52
  1. What kinds of relationships can we represent in a database?
    In database the relationship represented is how the inter tables connected. It could be a one to one relation, one to many and many to many relations.
  2. When do we use “One to One” relationships? Give an example from the real world.
    One to one relation means if you have a customer with its primary address. In database you would see a customer table will have something probably call the address id which links to address table and to the record.
  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?
    As each customer only have 1 address. With the customer_id in the order table you can look for the address_id which can use to look up the address of the customer.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Example of one to many is that customer have multiple contract details, e.g. email, mobile, work number, house phone.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Product in orders table.
  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.

#53

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.
Not very common, it is used to link for example a user to his social security number

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 need as reference to matching records in the address table.

Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
One to many = owner that owns more than 1 vehicle
Many to one = customers that order the same kind of pizza at the restaurant

Give an example from the real world when would need to use a “Many to Many” relationship.
In the restaurant, all orders from customers tables related to each kind of Pizza/dishes/food

What does items_orders table do?
create a “Many to Many” relationship between the items and the orders