SQL Relationships - Reading Assignment

  1. One to one, one to many, many to one, many to many and self referencing.
  2. A unique user and their address.
    3.The customer id is a foreign key in the customer table. The customer id relates to the customer
    table where the customer id is a primary key and shows the record of attributes about that specific customer.
  3. When one person makes multiple orders at a shop.
  4. Each order can contain multiple items and each item can also be in multiple orders.
  5. It creates the relationship between the items table and the orders table,both sides of this table.
1 Like
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships

A webstore that has one table for customers and stores their addresses in an another table.

that is the Foreign key that refers to the other table with the customers addresses

Webstore when customers can make multiple orders OR an order can contain multiple items

Webstore when customers can make multiple orders AND they can contain multiple items

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/self referencing
  1. When do we use “One to One” relationships? Give an example from the real world.**
    -Students Name Table, Students Contact table
  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?**
    -customer_ID is a unique identifier for the customer. This is used for the key. Each customer record also has a field address_id, this is the key for the address table, this is where the address for the selected customer can be found.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.**
    -Let’s take Registration of Students for Classes. Each Student registers for may classes. Each class has many students registering.
  4. Give an example from the real world when would need to use a “Many to Many” relationship.**
    -Let’s take Students and Classes. Many students take the same class, at the same time a student takes many classes, during one semester.
  5. What does items_orders table do?**
    -Adds items to orders.
1 Like
  1. One to One Relationships
    One to Many and Many to One Relationships
    Many to Many Relationships
    Self Referencing Relationships
    2.one to one is primarily just the id with a name and address
    3.Id is used to identify the customer to the information that is stored according to the ID it is an identifier to the specific data
    • Customers can make many orders.
      Orders can contain many items.
      Items can have descriptions in many languages.
      One to Many" relationships.
      Each customer may have zero, one or multiple orders. But an order can belong to only one customer.
      via a unique ID.
      5., each order can contain multiple items. And each item can also be in multiple orders.
      For these relationships, we need to create an extra table:
      The Items_Orders table has only one purpose, and that is to create a “Many to Many” relationship between the items and the orders.
      6.items order has the purpose to create 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, one to many, many to one, many to many, self referencing
  • When do we use “One to One” relationships? Give an example from the real world.
    Used when one element is unique/ there is only one like it and the other is variable, Country to GDP
  • 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 id is a foreign key, used to tie other tables without having to repeat the entry of the redundant data related to the id. Saves time, money and effort
  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many to one…FEDX… may want to know all the customers living in a common local area ( city, zip code,street) to improve delivery and cost/ delivery.

One to many…Travel industry may want to know where each person travels to in order to build packages to promote some areas. So each traveller may go to many places The tables would allow them to visualize areas they want to promote.

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    Retail stores…To manage product movement they would need several tables connected.
    Customers/item, items/instock/, items in inventory store /warehouse and so on.
    Allowing better control through many item/order tables related to each other.
  • What does items_orders table do?
    It is the base to the creation of Many to Many databases.
1 Like
  1. One to One Relationships, One to Many and Many to One Relationships, Many to Many Relationships, Self Referencing Relationships
  2. Customers table and the Addresses table. If each address can belong to only one customer, this relationship will be a one to one.
  3. The customer id relates to the customer table where the customer id is a primary key and shows the record of attributes about that specific customer.
  4. An e-commerce website where customers can make many orders, orders can contain many items, items can have descriptions in many languages.
  5. When each order can contain multiple items. And each item can also be in multiple orders.
  6. It has only one purpose, and that is to create a “Many to Many” relationship between the items and the orders.
1 Like

Reading Assignment: SQL Relationships

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

One to one, One to many, many to many, self referencing relationships.

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

A order id can have a one to one relationships, if a customer buy something and are in a database, the order ID have a direct relation to only one customer.

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 get a one to one relation between customer and address, and address_id it’s used as a foreign Key in the customer table, to link the address to the user. This to be able to have two different tables for users and addresses.

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

In a bank database, where all my own transaction are related to my userID, one person many transactions.

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

On Ivan on Tech Academy, there are some kind of database that keeps tracks of all students , and all courses. As a student can register for many courses and Ivan have many students. So many students can register for many courses and gain good knowledge by doing so

6.What does items_orders table do?

To create Many to Many relationships between items and 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.****
    In a “one to one” relationship, an entry in table A can have only one match in table B. In the real world a passport or a national ID should normally match to one person only.

  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 is a foreign key because although it’s from a different table, it is related to the customer table. These ensures that there is no data redundancy.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.**
    A customer may make an order with many different items in Amazon. In the products table, it will not be necessary to write the full names of the customer, all that is needed is the customer_id from the customers table.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.**
    Multiple customers order similar items in Amazon.

6 What does items_orders table do?**
This is a cross reference table which links the order and items tables.

1 Like
  1. The database relationships in the article are, one to one, one to many, many to one, many to many, and self referencing.

  2. A one to one relationship for example is when you have a table of sprockets and widgets and table B would be a list of dates that the sprockets and widgets were recieved.

  3. The customer ID is for organizing customers and is numerically related to the address ID.the adress IDs are kept separate for shipping and mass advertisement etc.

  4. A many to one/ one to many relationship is like, when a tire dealer has multiple orders to the tire manufacturer for different customers.

  5. The best way I can think to describe many to many relationships is ordering groceries on amazon.

6.An items order table would definitely help with inventory.

1 Like
  1. One to one, one to many, many to one, many to many and self referencing relationships.

  2. We use one to one relationships when one record in one table is associated with one and only one record in another table. An example would be a customers table and an addresses table, where one customer can have one and only one address.

  3. The customer_id column is a primary key in the customers table and is used to uniquely identify a customer. However, it is not used to connect customers to addresses. The column address_id is the one that is used for this purpose. It is a primary key in the addresses table and a foreign key in the customers table, meaning it establishes the relationship between a given customer and a given address.

  4. An example would be an eCommerce website where a customer may have zero, one or multiple orders. Multiple orders may exist for the same customer, however an order can only belong to one customer.

  5. Using the above example of an eCommerce website, each order can contain multiple items. And each item can also be in multiple orders.

  6. The items_orders table establishes a many to many relationship between orders and items.

1 Like
  1. What kinds of relationships can we represent in a database? -
    -one-to-one
    -one-to-many
    -many-to-one
    -many-many
    -self reference

  2. When do we use “One to One” relationships? Give an example from the real world.- If you have a sports team, you want the adress to each member of the team. John lives in aska street. John is one item and aska street is one item. One-to-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? - When you have large volume of customers, you may end up with customers that have the same name or very similar name. In some cases it can be like that with addresses also. And that’s why it’s more practical to give each of these items an unique id in the database to avoid confusion and make the database more organised.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    -One-to-many: One customer orders 10 different products online.
    -Many-to-one: One item in a store is ordered by many customers.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    -It can be many customers that orders several or many items and many items can be ordered by many customers
    -A blog can have many users and one user can be a user of many blogs

  6. What does items_orders table do?
    -Its the tool you use to create 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

If each address can belong to only one customer, this relationship is “One to One”.

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

3.a.

It is a field in one table that uniquely identifies a row of another table or the same table. 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.

Customer can make many Orders.

Orders can contain many Items.

Items can have descriptions in many languages.

You need multiple instances on both sides of the relationship for example ordering a

Pizza with different Items on top.

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?
    Answer -
  • 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.
    Answer - we are using this relationship when we have a situation that can be described as “one key= one value”. The most exemplary situation will be when we are dealing with person’s date of birth and the respective SSN.
  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?
    Answer - I guess there is a typo in the question, since what is being asked about, most likely is “address_id”. If so, then it is called “Foreign Key” which is used as basis for linking two tables.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Answer - “A list of all my passwords. All those passwords belong to me, but I own many passwords.”
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    Answer - Customers of all restaurants in a cirt. A customer in that city can visit many restaurants, thus we can say that a restaurant potentially should have many customers.
  5. What does items_orders table do?
    Answer - creates “many to many” relationship.
1 Like
  1. What kinds of relationships can we represent in a database?
    One on 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.
    A customer and their email
  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 the customer can easily be identified. The name is just an attriubute of the customer. It is better because there can be more customers with the same name or adres. The ID is the overall identifier of the customer.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    -Customer orders multiple times.
    -One order consists of many different products that are sent individually
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Orders from one country consistent of a lot of customers can have a relationship with the warehouse locations
  6. What does items_orders table do?
    Connects items to orders so that multiple items can be in an order and multiple orders have the same item. Creates 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. We use one to one relationships when one row from a table can be linked with only one row in another table and viceversa.
    Example : one individual and his passport.

  2. We have that name column “customer_id”, because in this way it’s easier to find the customer if by chance 2 or more customers have the same name. So each customer has an unique customer id. This is called a foreign key and it’s defined in the second table.

  3. History teacher and students from a small school.

  4. A student can register for many classes and a class includes many students.

  5. Has only one ppurpose: 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
	
2. When do we use "One to One" relationships? Give an example from the real world.
	a. If a entry of one tabel belongs only to one entry in a other tabel
	b. e.g. I've a dog -> this dog belongs only to me
	
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. it is used as key for the table entries -> a key is always unique
	b. as a freign key address_id is used -> this is the reference to customer address

4. Give an example from the real world when would need to use a "Many to One/One to Many" relationship.
	a. i use one car -> this car is used from others also

5. Give an example from the real world when would need to use a "Many to Many" relationship.
	a. Visitors of a shopping center
	
6. What does items_orders table do?
	a. it covers the many to many relationship. the reason for that is that in each table you need an unique key and the database has to be normalized. 
	b. in this table the whole row is a key
1 Like
  1. 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.
    Where a data set can belong to one person (item) we use a one to one relationship. For example in a database of my friends if the address can belong to just one friend. Then there is a one to one relationship of the data set (address) to one friend of mine.
  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?
    Customer_id is used to identify the customer so that there is no need to reenter the customer data every time the customer makes an order. It is used to connect customers to addresses by creating a Foreign Key in the order table.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A class of students each studying different subjects with different modules and each module having a description.
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    An order of cinema tickets for a group of adults and children sitting on different rows.
  5. 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
  • What kinds of relationships can twe represent in a database?
    One-to-one, one-to-many, and many-to-many

  • When do we use “One to One” relationships? Give an example from the real world.
    A company offers only one service, and that service is only offered by that company.

  • 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? He wants the server to react one to one, mening only one customer and one adress are in a relationship. making sure it cant be duplicated.

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

When one customer orders more than 2 items in one order.

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    One singer can have one or many albums and an album can have one or many artist.

  • What does items_orders table do?
    It have many to many relationship between the items and the orders.
    Making a list on which items have ordered

1 Like
    • One to One Relationships
    • One to Many and Many to One Relationships
    • Many to Many Relationships
    • Self Referencing Relationships
  1. 1 to 1 relationship is when one value can only belong to one other value. i.e. In the United States, each citizen is issued a unique social security number at birth.

  2. The customer ID gives a unique number value to each customer, allowing us to easily locate that customer. We can then create other tables referencing the unique customer ID to join with other relationships. i.e. customer ID 101 is joined with address ID 301 etc.

  3. A one to many relationships can be visualized by customers shopping online at a jewelry store. Each customer can have multiple orders with multiple items in multiple languages.

  4. The relationships between items, & their item orders On a platform like amazon would be an example of many to many relationships.

  5. The items_ordered table creates a “many to many” relationship between the items and the orders.

1 Like
  1. one to one, one to many & many to one, many to many, Self referencing
  2. calling a friend, each friend has their own phone number.
  3. Foreign Key is like a link pointer to the other table
  4. Giving out Halloween candy, everyone gets some candy but some people can’t have certain kinds.
  5. When I get dressed I need multiple pieces of clothing but I also need them to match and be appropriate for weather, daily activity etc.
  6. To create a many to many relationship.
1 Like