SQL Relationships - Reading Assignment

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

There are several types of relationships that can be represented in a database. Some of the most common ones are:

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

We use One to One relationships when a field can only have one relation with an attribute. For example, name of father; there is only one valid name related to each record.

  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 functions as a primary key in the customers table; it’s the record that uniquely identifies each customer.

That unique reference is used as a foreign key in the customer address table to join the data of customer and address

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

- Many to One: a person that has several credit cards; all spending of each card will belong to the same person

- One to Many: orders on an e-shop, as one customer might have several orders

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

- Many to Many: several people can be signed for a course; this course might have several teachers giving the lecture and each teacher might give another courses as well.

  1. What does items_orders table do?

The items_orders table establishes the relation between the list of unique order id with its corresponding unique item id. The objective is to set a table with many to many relationship.

1 Like
  1. Relationship types are:
  • One to One
  • One to Many
  • Many to One
  • Many to Many
  • Self Referencing
  1. We use a “One to One” relationship when a single dataset from the table can relate to only one dataset. i.e., A Customer can have only 1 Date of birth.

  2. The address table has a column for address_id, and that address_id is a column in the customers’ table, a Foreign key to the address table.

  3. One to Many - a customer can speak many languages.
    Many to one - Many cars can be owned by a single customer.

  4. Many to Many - a customer can own many joint accounts, and a joint account has many owners.

  5. The items_orders table links each order to the items included in the order.

1 Like
  • What kinds of relationships can we represent in a database?
    One to One Relationships
    One to Many Relationships
    Many to One Relationships
    Many to Many Relationships
    Self Referencing Relationships
    (Is this like a function, where input is mapped to output with different types of relationships?)

  • When do we use “One to One” relationships? Give an example from the real world.
    We use this type when we want to define a strict relationship with 2 entities only. An example would be Wallet address and its ETH balance.

  • 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 key to access the customer name (value). It also contains another key (address_id) to a different relationship table (address), to connect customers to their addresses. The address_id is a foreign key in the customer’s table. In which it’s value pair is in another table

  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    An example of one-to-many would be a Teacher to his/her multiple students
    An example of many-to-one would be Students enrolled in a single Class

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    An example of many-to-many would be each student having multiple subjects (Math, English, Science, etc.), and each subject being take up by multiple students

  • What does items_orders table do?
    Create a “Many to Many” relationship between the students and the subjects.

2 Likes
  1. The different types of relationship that can be represented in a database are:
  • One to one
  • One to many
  • Many to one
  • Many to many
  • Self referencing
  1. We use one to one relationships when there can only be one relationship between two entries, for example a person and their passport number.

  2. Each customer is given a unique customer_id number, it is a foreign key that is used for relationships between tables.

  3. An example of a one to many/many to one relationship would be a database that stored addresses and the people who live in those addresses.

  4. A many to many relationship could be used in a database storing which people will be eating at a restaurant and what they will be eating. One person may be eating many different foods, and one food may be eaten by many different people.

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

1 Like
    • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. When an entry has one relationship only. Bank- customer name- account balance

  2. To identify a customers address via an internal ID. An ID will belong to one customer only therefore one address.

  3. I can create many orders from amazon but those orders will be delivered to 1 customer myself Therefore satisfying one to many and many to one.

  4. I can create many orders from amazon and each of the orders can have many items. Therefore satisfying many to many.

  5. Many to many. Orders of items, stock levels

1 Like

1.What kinds of relationships can we represent in a database? one to one, one to many, many to many & self referencing

2.When do we use “One to One” relationships? When an entry has only one relationship. ex. contact name & their 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 address table has a column for address_id, and that address_id is a column in the customers’ table, a Foreign key to the address table.

  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship. One to many: Customer has multiply orders
  2. Give an example from the real world when would need to use a “Many to Many” relationship. cooking recipes. each recipe can contain multiple ingredients. And each ingredient can also be in multiple recipes
    6.What does items_orders table do?It is used to create a “many to many” relationship between the items and the orders.
1 Like

one to one
one to one
one to many, many to one
many to many
self referencing

A unique entire specific to only that property for example Bank details or your national insurance number.

The foreign key, customer id is so you can create a relationship between that unique customer and other tables.

when buying from Amazon or eBay you can buy from different sellers and locations at different times, and sent to different address, but all being linked to just one id.

a restaurant has many customers, each customer can eat many items from the menu.

It creates the many to many relationship linking the respective items to orders

1 Like
  1. What kinds of relationships can we represent in a database?
    A Relational database can have one-to-one, many-to-one, many-to-many and self-referential relationships.

  2. When do we use “One to One” relationships? Give an example from the real world.
    We use one-to-one relationships when one attribute is unique to one record. For example, a social security number or tax id can only be associated to one 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?
    The customer_id column is a unique key for the customer and the address_id column in the customers table is a foreign key that corresponds to a unique key in the addresses table. This foreign key allows for quieries to find the customer’s address by matching the foreign key ‘address_id’ from the customers table with the unique key in the addresses table.

  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 one-to-many relationship is an Amazon order. One Amazon customer can have zero or more orders and each order can have multiple items.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    A real world example of a many-to-many relationship would be to query parents and children tables. Parents can have one or more children and children can have one or more parents.

  6. What does items_orders table do?
    The item_orders table is used to store the many-to-many relationship between the order ID and the items each order contains.

2 Likes
  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 from the real world.

2 When do we use “One to One” relationships? Give an example from the real world.
A) When there can only be one relationship between an entry
B)D.N.A.test i assume?
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 keeps the one to one relation ship only allowing one addres per id or vice versa.
4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
A customer who buys many items
5. Give an example from the real world when would need to use a “Many to Many” relationship.
twitter has many subjects that has many people following these subject ,people and or company .
6.What does ‘items_orders’ table do?
It creates a many-to-many relationship

1 Like
  1. One to one Relationship, one to many Relationship, many to many Relationship, Self Referencing Relationship

  2. One to one Relationship is used when we have one entry can belong only to one other entry. Individual people with IBAN

  3. This is the reference between the 2 tables that connects them

  4. Consider an e-commerce website, with the following:

    Customers can make many orders.
    Orders can contain many items.
    Items can have descriptions in many languages.

  5. Many to many relationship could be customers in an ice cream shop. Each one can order flavors that another could also order

  6. 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. kinds of rels: one to one, one to many, many to one
  2. one to one relationship example: customer and his/her address
  3. the customer id is the foreign key. the foreign key is used to retrieve info in a different database.
  4. many to one: ex: many different people ordering the same product. one to many: one person ordering many, different products.
  5. many to many: many people calling their friends using their cell phones.
  6. creates a many to many relationship
1 Like
  1. There are 4 main types of relationships
    One to One
    One to Many and One to One
    Many to Many
    Self-Referencing

  2. Members of a certain congregation, entity, or faction, like a school, or a church, or a business. Each member has uniquely singular mediums of identity within each realm, aka data within that space that they have a unique, one-to-one relationship with.

  3. It’s a foreign key, used to apply data across multiple relationships.

  4. A real-world example of a many-to-one relationship is Amazon. They serve countless numbers of people al over the world and fulfill even greater multiples of orders.

  5. Many to many is the next level on top of amazons protocols.

  6. Creates 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
  2. When do we use “One to One” relationships? Give an example from the real world.
    Buying a second-hand car from an individual
  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?
    By connecting customers name to the addresses
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many students attending an English class
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Amazon online store
  6. What does items_orders table do?
    It links customer to the right item boughtstrong text
1 Like

Answer for SQL reading Assignment

  1. One to One, One to Many, Many to Many, & self-referencing.

  2. We use one to one relationships when we want only one key to represent only one value. An example may be a user to an email address Or a serial number to a product.

  3. Because there is a relationship between the two tables. The foreign key is used to join the customer’s id to its corresponding address.

  4. Amazon is an example of a Many to One/One to Many relationships. One customer may place an order that can contain many items.

  5. An example of a many to many relationship is where you have multiple customers, that place different orders which can contain many different items and each item can be in different orders.

  6. Matches an orders_id to its item_id

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 social security number can only have one person assigned to that 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 is the primary key and associates that customer with that id. You can then identify that customer using that id with all future transactions.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Amazon orders is a great example. I often place an order on amazon with a couple of items. I then forget an item and place another order. A few days later I may place an additional order. Each time I am identified by my customer id and I can have many orders, many addresses, many items and so on.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    In my amazon example above there could be the same items I ordered connected to other orders. Many items to many orders.
  6. What does items_orders table do?
    The items orders table only purpose is to create the many to many relationships.
3 Likes
  1. What kinds of relationships can we represent in a database?
  • one to one
  • one to many
  • many to many
  • self reference
  1. When do we use “One to One” relationships? Give an example from the real world.
    We have an e-commerce website with different items which have prices. The item_id would have a one to one relationship with the price_id.
  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 foreign key in the customer’s table. It can be connected to a primary key in another table. This is called relationship integrity and it makes sure a specific customer_id is related to a specific address_id.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
  • Many to one: Many different orders can be related to one order
  • One to many: one customer can be related to many orders.
  1. Give an example from the real world when would need to use a “Many to Many” relationship.
    In a restaurant you could have product butter in recipe browny and in recipe eggs benedigt, but also product butter and product eggs in recipe eggs benedigt.
  2. What does items_orders table do?
    creates many to many relationships
1 Like
  1. One to one, many to one, one to many, many to many and self referencing relationships.

2.you can use one to one for people’s address.

  1. That is what ties the customer to the address. In the data base

  2. Online grocery shopping. 1 customer picks many items to buy

5.Like online grocery shopping again many people can choose the same item so many to many

6.items order table is only to create many to many relationships

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.
  • a name matched to a passport number or national ID 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?
  • links information from 2 different table
  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
  • Grocery shopping. People can choose to purchase multiple products and products can be purchased by multiple people.
  1. Give an example from the real world when would need to use a “Many to Many” relationship.
  • When purchasing items online, the website would be required to use “many to many” relationships.
  1. What does items_orders table do?
  • Links “orders” table and “items” table
2 Likes
  1. We can represent one to one, one to many, many to one, many to many relationships
  2. One to one would be when each entry field can belong to only one customer. Ie: individual people and their social security numbers
  3. The customer_id in the customer table is called a foreign key and is used in all kinds of database relationships. It’s job is to enforce referential integrity between data in two tables. 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 relationshp between the two lables.
  4. The Many to One/One to many relationship is the most commonly used type of relationship. An example would be with ecommerce: Customers can make many orders, orders can contain many items, items can have descriptions in many languages.
  5. A real world example of Many to Many would be you may need multiple instances of both sides of the relationship. For example, each order can contain multiple items, and each item can also be in multiple orders. IE ordering a pizza with different toppings
  6. items_orders tables only purpose is to create a Many to Many relationship between the items and teh orders.
2 Likes
  1. What kinds of relationships can we represent in a database?
    We can represent
    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.

  • Information about the ownership of an NFT, the address number will point directly to the token ID(NFT) owned by that address*
  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?
    Having a costumer_id allows to easily connect the costumer to the value costumer_address

  2. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Amazon costumers can make orders, those orders can contain many items and those items can come from different jurisdictions

  3. Give an example from the real world when would need to use a “Many to Many” relationship.
    *The Amazon order can contain many products and each product can also be in different amazon orders *

  4. What does items_orders table do?
    It creates a many to many relationship between items and orders

2 Likes