SQL Relationships - Reading Assignment

  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

  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 .

  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.

  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.

  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.

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.

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

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.

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

  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.

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

  1. What kinds of relationships can we represent in a database? 1. One to One 2. Many to One/One to Many 3. Many to Many 4. Self referencing
  2. When do we use “One to One” relationships? Give an example from the real world. A unique user and his passport 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 attribute “customer_id” identifies a single customer in the “customers” table where it’s a primary key. In the “customers” table there are also the attribute “address_id” that’s a foreign key to the “adresses” table where for each “address_id” there’s an address that’s in this way connected to the relative customer.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship. The children and their mother in a community of people.
  5. Give an example from the real world when would need to use a “Many to Many” relationship. The groups of friends in a community of people.
  6. What does items_orders table do? “Items_orders” table creates a “Many to Many” relationship between the items and the orders.
  1. There are several types of database relationships. Today we are going to cover the following:
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. Customer -> Address

  2. By Foreign keys

  3. Many people may live on one address, one person may have multiple addresses.

  4. Drivers to cars.

  5. Creates a “Many to Many” relationship between the items and the orders.

  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.
    When we want to connect one database to another single database.

  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? To connect the address to the customers. The customer ID was used to display customer address in the customer database.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    When you place an order in a supermarket.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    When you record an item to cart in a supermarket

  5. What does items_orders table do?
    To create many to many relationships between Items and orders.

  1. What kinds of relationships can we represent in a database?
    1 to 1 relationships, 1 to many, many to many, self reference (hierarchical structures)

  2. When do we use “One to One” relationships? Give an example from the real world.
    1 to 1 is used when 1 object is linked to just 1 other object and the other way around.
    A car has just 1 unique VIN nr, and 1 VIN nr links to just 1 unique car. (so we have a table with cars and another table with VINnrs, we can just store those 2 things inside the same car 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?
    customer_id is the unique reference to a certain customer (primary key), in that way we can link to this customer in other tables by this ID. So a customer will be linked to an address by means of a foreign key that links the customer_id to the address_id

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A car (table car) can be linked to just 1 brand (table brands), but a brand can be linked to multiple cars

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Many to many is usually solved by creating a new link-table that links with 1 to many relationships to the 2 other tables that had a many to many relationship.
    example is a car (car table) has multiple options (options table), a car can have multiple options but those same options can also be applied on multiple cars. So we create a link-table that links the 2 together with the unique id of the car with the unique id of the option.

  6. What does items_orders table do?
    The table links items with orders. (link table between items table and orders table: many to many)

  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
  1. When do we use “One to One” relationships? Give an example from the real world.

One entry can have only a one to one relationship like name and age

  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?

An address_id is made to have a one to one relationship with the customer_id

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

When ordering items from amazon you could order one item or fill your basket with more than one item. At the same time if you speak a different language you can always switch languages to your prefered language.

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

When ordering on alibaba and bulk buying a few different items with certain specifications

  1. What does items_orders table do?

To create a many to many relationship where it has one purpose of being the mediator

  1. one to one, many to many, one to many, many to one, self referencing relationships
  2. when we have two tables, entry from the table1 belongs to another unique information from the table
    for example a person and a phone number.
  3. because we make relationships between the tables through IDs.
  4. one company has many employees (one to many)
  5. we have the table employees, and the table firm_cars. employees can borrow any car they choose which are available on the exact day. a different employee can borrow a different car, in one car can be sitting more than 1 employee at the same time
  6. its a relationship between 2 tables items and orders connected through their IDs, in this table we can see which items belongs to which orders
  1. What kinds of relationships can we represent in a database?
    One to one relationships, one to many relationships, many to many and self referencing relationships.

  2. When do we use “One to One” relationships? Give an example from the real world.
    People with their drivers license number or 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?
    It is the key which other tables can use to reference each customer from the customers table.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many students may attend one class. One teacher may teach many students.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    For products on a website. Each order may contain multiple of the same product and many orders can also order that same product.

  6. What does items_orders table do?
    It is the table which allows us to create many to many relationships between the order table and the item table.