SQL Relationships - Reading Assignment

  • One to one relationships.
  • One to many relationships.
  • Many to many relationships.
  • Self-referencing relationships.
  1. Linking customer name and address as each address can only belong to one customer.

  2. A unique foreign key is used to link the customer id with the the customers address. This establishes the basis for one to one relationship ass customers cannot have more than one address, thus being defined as a one to one relationship.

  3. Linking multiple orders to a single customer.

  4. Linking the item ordered with the order number. many items can be ordered in many orders.

  5. item_order column creates the relationship between orders and items 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.
    a customer has an address
  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 address table would have column called customer ID this is necessary in order to connect an address to a customer in the customer table
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    One customer can have many orders
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    an order has many items and an item may belong to many orders
  6. What does items_orders table do?
    it connects to both items and orders and would typically have a one to many relationship with a customer or belong to one customer since a customer can have many orders but an order cannot have many customers
1 Like
  1. One to one, One to many, Many to many, Self reference
  2. When each field in a given table corresponds only to one field on another table. For example, in a family (with not twins, triplets…or any adopted child): Sibling name, and age have a one to one relationship.
  3. The customer ID can be used as a foreign key. Meaning it can be a point of reference to retrieve info as to, in this case, customer address. It is a unique number for each customer.
  4. If one person orders 3 different pizzas for example.
  5. If I order pizza A and B and my brother orders Pizza B and C
  6. Create a many to many relationship between items and orders
1 Like
  1. one to one, one to many, many to one, many to many and self-referencing relationships.
  2. unique user and their address
  3. unique customer id in customers table is a foreing key. these keys can be used in many database relationships.
  4. example would be customers can make many orders and the orders can contain many items.
    /one to many could be a refering link to a website.
  5. example same item was ordered from the website by many customers.
  6. create many ti many relationship between items and orders
1 Like

Note: HAHA I read past the “self referencing” part and was killing myself learning it :slight_smile:

  1. 1:1; 1:many; many:1; many:many. Ref:Ref.
  2. Real world 1:1 example could be a person and their email address.
  3. Apart from identifying a Foreign key, one reason a customer_id might be used instead of customer_name is privacy.
    by using id numbers in tables you can then develop name/id relationships in another table to increase security.
  4. Many students taking a class at Ivan on Tech Academy. One student taking many classes at IOTA.
  5. A many to many relationship could be posting links you like on facebook that others like or post themselves.
  6. The items_orders table leads to the many to many relationship between the items table and the orders table.
1 Like
  1. Kinds of relationships that can be represented in a database include;
  • One-to-One
  • one-to-many/many-to-one
  • many-to-many
  1. a. One-to-one is used when a value in one table corresponds to only one value in the related table.
    b. An individual and his/her BVN(bank verification number)

  2. a. This is a Foreign Key and it’s purpose is tag the column so two pieces of data can be linked between tables.
    b. The Foreign key column is a collection of unique identifiers for each customer and is used to match data on the corresponding address column.

  3. A BVN(bank verification number) linked to several accounts of an individual, this is an example of one-to-many type of relationship.

  4. Also many BVNs can be linked to several accounts owned by several individuals, this is an example of many-to-many type of relationship.

  5. It is used to establish the many-to-many relationship between Orders and Items.

1 Like
  1. What kinds of relationships can we represent in a database?
    The different kinds of relationships that can be represented in a database are, One to One, One to Many and Many to One, Many to Many, and Self Referencing Relationships.
  2. When do we use “One to One” relationships? Give an example from the real world.
    An example of a One to One relationship would be a company documenting a customers name and connecting their address to their name.
  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?
    They did this to create a “Foreign Key” which is used for different database relationships. These Foreign Keys are used to ensure referential integrity of the data.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    An example of a Many to One relationship could be an individual who has many different orders in the transaction history.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    An example of a Many to Many relationship would be a list of students and the variety of classes that each student is enrolled in.
  6. What does items_orders table do?
    The items_orders table’s purpose is to create a Many to Many relationship between the items and the orders.
1 Like
  1. one-to-one, one-to-many, many-to-many.

  2. When something is connected to one specific thing. Given example is the one of a shipping address to a single customer.

  3. The id (Foreign key) helps with enforcing connections. Especially useful since the database has an easier time looking for an int rather than a string. Since the key identifies the customer it is easy to make all connections to it as needed.

  4. Let’s say we have a bunch of areas which has data specific to themselves but is needed to be gathered and compared with each other as well. Let’s say tournament data for local regions. Local regions would have their own data regarding their region but for larger events a greater manager for multiple regions would need the data from each region and vice versa as the bigger event would need to send data to each individual region.

  5. Let’s pick a similar case as the one above if multiple players plays in multiple regions then a many-to-many would be better to be able to appreciate the player’s skill as the results of matches in multiple regions would be needed to be registered for multiple players

  6. The table relates items to their specific order as given by the order (possibly due to multiple types of orders existing). Also may simply assist the many-to-many relationship.

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.
    each person has his own mobile telephone number that is personal, no 2 people have the same mobile telehphone number

  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 standerize and make it faster to search for.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    many products can be bought by one customer
    one product can be bought by many customers

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    a peacce of clothing can have many different colors and sizes and be one of many clothings in a line

  5. What does items_orders table do?
    it gives an id to each item in a order, each order can exist of many items

1 Like

1: Relationships:

  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. Its used when an entry can be used for one object. E.g when a customer is linked to an address they will need only one address.

3.Customer_id is a foreign key. This foreign key is assigned to each customer creating a link between the customer and tables.

  1. Example is when a customer purchases products online. This customer can purchase multiple items within a single order.

5 Online store may have multiple orders for a variety of products from multiple customers.

6.The Item_orders table allows the many to many function to resolve the relationship between orders and items.

1 Like
  1. Relationships in database:
    a. one-to-one
    b. many-to-one and one-to-many
    c. many-to-many
    d. self referencing relationships

  2. One-to-one relationships is used in case were each record relates only to 1 entitie ex:
    1 airline has 1 home airport

  3. Custumer-id column is gathering all costumers by a number, not a full name clmn + adress clmn so the computer that is reading it needs to focus on 3 or 4 digit number not on full information wich cointains many digits to read, this makes the whole process faster and cheaper.
    Costumer adress may be written in to costumer-id or can be related by another foreign key: adress-id that represents full adress data in other table.

  4. 1 airline has many airplanes and many airplanes can fly on 1 route.

  5. Many airplanes can fly on many routes.

  6. Items-orders Table creates a Many-to-Many relation between these two. Item-order column is a graphic representation of item-order relation.

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.

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

Basic information requirement where there is a simple one to one, or exclusive, relationship (I.e. - each individual has a unique drivers license number or social insurance number).

  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?
    A separate table contains customer addresses. In this case, customer_id is also a field in the address table, as a foreign key, linking the customer information across two tables. Customer address could also exist as a field in the customer table.

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

Sales: One purchase order can have many products. Many products appear on one purchase order.

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

Sales: Many purchase orders can have the same product, which means a many specific product codes can appear on many purchase orders.

  1. What does items_orders table do?

The items_orders table is created specifically to tie the list of order numbers to their corresponding items, thereby creating the many to many relationship 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.

For things such as email addresses or phone numbers for customers where each customer has only one phone number or address and each phone number or address is specific to that customer.

  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?

The customer ID is the key field in the customers table and can be used to reference the particulars of that customer in other tables. The address of the customer is stored in the applicable row of the customer table.

  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    An example would be where one customer has many orders.

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

Many to many would be applicable where a customer has many orders and each order has many items.

  1. 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. One - one; one to many and many to one; many to many and self referencing relationships.

  2. a. When one entry is related to only one entry
    b. Persons and age.

  3. Foreign Key are used for all kinds of database. It is used to connect with another table with uniques entries.

  4. My crypto portfolio, can have an Id link to a coin or token, and then each coin with its value and my orders and date in other tables.

  5. ordering multiple items from amazon

  6. it’s a record of every times sold.

1 Like
  1. a) One to One relationship
    b) One to Many and Many to One Relationship.
    c) Self-Referencing Relationships.
    d) Many to Many Relationships.
  2. When the entry field belongs to only one customer then we use One to One relationship. Eg: A customer and his address.
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 an entry is always specific to another. For example car owners and their number plates

  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 serves as a label for the attributes. If there is another table that stores addresses, customer_id will 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.
    Parent- children

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Favourite artists. One may have many favourite artists, and an artists can be liked by many.

  6. What does items_orders table do?
    Create relationships between items and orders

1 Like
  1. One to one, one to many and many to one, and many to may relationships.
    2)In schools students are usually assigned a student ID number .For, example students name pertains to 12345.
  2. The customer_id quarries the data in that row.
  3. A customer orders paper towels, toothbrush and other essentials. this one order has multiple items with each item pertaining a description.
    5)Take the example I gave in question 4. Now each item has a purchase history from different people.
  4. Items_orders connects orders and items.
1 Like
  1. One to One
    One to many
    One to many
    Many to many
    Self Referencing

  2. One to one relationships are given when there’s one record that can only belong/be related to one other record. Anyone’s National ID number is only related to each person separately.

  3. The Costumer_id works as the “foreign key” that refers to the matching record in the Costumer’s table, when written into another table.

  4. Many to one example may be when you order a bigmac in Mc Donald’s, you then go and order another one and later go and order another one. 1 costumer = many orders.
    But then you go and order 4 burgers in only one order. That’s One to many, becasue there are multiple items in only 1 order.

  5. When there are multiple students enrolled to one class, but many of those students are also enrolled to other classes.

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

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.
    A unique user and their address
  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?
    Foreign keys are used for all kinds of database relationships. It is used to ensure referential integrity of the data.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    In the case of a college. Students may have one course, but one course may have many different classes. Or another case, each course may have many lectures.
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    lots of clients, made lots of orders, or an item was ordered many times and by many people.
  5. What does items_orders table do?
    It connect to orders id with the items id.
1 Like
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. It can be used when there is only one relation between an entry. For example VAT number of company in company registry.

  2. This is unique number or Foreign key to link particular customer with particular address.

  3. This is most used type of relationships. E.g. it can be used to store information if/when which citizen have taken one, two or non of vaccine shots.

  4. Customers ordering food from menu in restaurant.

  5. It connect Orders and Items tables to show which items are included in orders.

1 Like