SQL Relationships - Reading Assignment

  1. One to one
    One to many
    Many to many
    Self referencing

  2. When there is an attribute with a unique identifier.

  3. It is used to ensure referential integrity of the data, it is an expression of the relationship of entities in different tables.

  4. A. Different sections of a firm working in a particular section.
    B. An employee who works in a different section.

  5. A specific item can be in different sales, different sales can have a same item.

  6. Makes “many to many” connection between order id and item id.

1 Like
  1. What kinds of relationships can we represent in a database?
  • one to one /many to one/ many to many/ self-referencing relationships
  1. When do we use “One to One” relationships? Give an example from the real world.
  • adress to 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?
  • named foreign key - this is used to use the same data on many tables.
  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
  • customer support to on customer. Or orders at Amazon in relation to one customer.
  1. Give an example from the real world when would need to use a “Many to Many” relationship.
  • for example carparts in different cars.
  1. What does items_orders table do?
  • make many to many connections between items and 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 and self-referencing.

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

When only a single relationship can exist between two entities. The article uses an example of a customer to address, but this is inaccurate as they could have two or more separate customers at the same address. A better example might be a customer to an email address or a customer to card details.

  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 column is referenced next to the address to specify the customer the address relates to.

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

One customer can have multiple orders from an ecommerce store.

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

Multiple orders can contain multiple items.

  1. What does items_orders table do?

It exists purely to create the relationship between the unique item ID and the unique order ID, therefore recording every item that was part of every order.

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 are all different kinds of relationships we can represent in a database.

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

One passport id for each individual.

  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?

To keep track of each customer. For each customer id there’s one address id.

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

Many social media accounts that belong to one person.

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

Many ingredients for many recipes.

  1. What does items_orders table do?

It keeps track of which items where ordered in which orders.

1 Like
    • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. Direct unique input relating to the specific relationship like passport, license
  2. refers to the matching record in the Address table that can be linked with others
  3. Bulk order to people like mail, emails, uni platform login
  4. Specific same order of equivalent but added different outputs
  5. Shows what orders 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

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

  • When the requirements call for an absolute one to one relationship between entries
  • A driver’s license or 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.

3a/ Why?

The author is using what is called a "foreign key " or primary key that is used to enforce referential integrity between the data in two tables.

3b/ How is it used in order to connect customers to addresses?

This will allow the tables to be linked, which allows for the two tables’ data to be queried against.

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

A customer buying more than one order online.

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

A yoga studio member can attend many different yoga classes and each yoga class has many different members attending.

6/ What does items_orders table do?

It is used to determine the Many to Many relationships between the “order_id” table and “item_id” table.

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 real world example would be when you have one of those grocery cards you scan for coupons. It is a one to one relationship between what you purchase and your name.

  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?

It is used as a foreign key. It is used to match it to the customer’s address.

  1. *Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    In the real world I am a college psychology professor. I could have one student take several of my classes.

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

Many of my students could take several of my classes.

  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

SQL Relationships-Homework

1-ONe to one, One to Many, Many to one and Many to Many
2- When one entry of one table has one only match or relationship with another table. For axample, Name of a person and his or her height or his adress.
3- Customers and adresses are separate tables, and customer_id is the data that links the first table (customers) to the second table (addresses)
4- A building of a specific address, has many tenants. that is a one to many relationship.
5- for instance a car dealer, has cars (models) and customers, a car model can have many customers, and a customer may have more than one model.
6- Stores all the items that have been ordered by customers.

1 Like
  1. One to One, One to Many - Many to One, Many to many
  2. a) when an entry can only belong to one field. Like customer A and his specific adress.
    b) Indviduals and their cellphone number
  3. a) It’s a foreign key to connect data from different tables.
    b) One field uniquely identifies a row of another table (or the same table) to reference in another table.
  4. It’s the most common, it refers to e-com shopping in the real world. A customer could have many orders. An order could have many items.
  5. This would be needed for the same scenario of the ecom narrative. Each order could have multiple items, and multiple items could be in multiple different orders.
  6. it creates a many to many relationship
1 Like
  1. One to One Relationships. One to Many and Many to One Relationships. Many to Many Relationships. Self Referencing Relationships.

  2. For example there’s a customer and address table. One customer can only one address.

  3. The customer_id is called a “Foreign Key”. Every row has a unique id. They are used to connect the relationship between tables. For example the address table as column customer_id. So you can assign every address to a related customer.

  4. A shopping database has a customer table and order table. One customer can have any number of orders.

  5. A shopping database has an order and items table. One order can be related to many items. Also, one item can be related to many orders.

  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 They types of relationships we can represent in a database are: One to One, One to Many/Many to One, Many to Many, and Self Referencing.
2. We use One to One relationships when there can only be one possibility for each field. Ex Name-Address
3. The column called “customer_id” is the Primary Key of the first table and is used as the Foreign Key in the second table to join the information.
4. A One to Many/Many to One relationship could be used in a situation where there is One customer who has many orders.
5. An example of when we could use Many to Many is when joining data from two tables containing multiple orders with multiple items on the orders and the multiple items even appear on multiple orders.
6. The items_orders table would have to be created be a Many to Many self referencing join requires a separate table.

1 Like
  1. One to One, One to Many, Many to Many, Self Referencing
  2. When one entity can only belong to one other entity and vice versa. Ex: If a person can only have one social security number, then there is a One to One relationship between the person table and the social security numbers table.
  3. The customer_id field is the primary key of the customers table. It has no use in that specific one-to-one relationship section. The field used to connect the customers to addresses is address_id and it is a foreign key in the customers table.
  4. A customer can have multiple orders but an order can only be linked to one customer.
  5. An order can have multiple products and a product can belong to multiple orders.
  6. It creates a Many to Many relationship between orders and items, allowing items to belong to multiple orders and orders to have multiple 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.
    customer - 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 Key” and it is used for all kinds of database relationships

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

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

  5. What does items_orders table do?
    store relationship items data and orders data

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 ref relationships

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

Customer name and their 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?

The customer_id contains name and address. That id is now connected (has relationship) to the address id in another table.

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

E commerce website: a customer and their many orders; each order contains many items

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

An order has many items and each item can also be in many orders

  1. What does items_orders table do?

This table establishes the many to many relationships

1 Like

1.- The kinds of relationships that can be represented in a database are:
one-to-one
one-to-many and many-to-one
many-to-many
self referencing
2.- One-to-one relationships are those that are unique or can be used as a key. The driver license of a person and their identity, is one-to-one.
3.- The customer_id column is to give each customer a unique identifier. These are used in order to assign an address to each customer_id. Customer_id to address_id can be one-to-many.
4.- Car registration plate number and car model is a one-to-many relationship.
5.- Color of a car, and car model is a many-to-many relationship.
6.- The items_order table registers the relationship of what was “purchased” in each order.

1 Like
  1. One to One, One to many and Many to One, Many to Many, Self-Referencing

2.a/ When an entry belongs to one customer.
b/Individual people and phone number.

  1. It is used as a foreign key and can make the relationship with other database.

  2. When you order more than one thing to the same order, or few people ordering same item in different orders.

  3. A person can do many exercises and each exercise hits different muscle group.

  4. It creates relationship between items table and orders table, both sides of this table.

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.

When one variable links to only one other variable. Say we have a customer who can only be linked to one 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?

The “customer_id” is a foreign key that creates a relationship with other tables such as the one for addresses. By having an addresses table each customer_id relates to one address.

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

An e-commerce website where different customers can buy a product or multiple products once or more than once.

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

On platforms like Amazon different customers may have different orders consisting of multiple products/items. Same items can appear in different orders and can be bought simultaneously by different customers with their own unique list of products per order.

  1. What does items_orders table do?

It creates a ‘many to many’ relationship between items and orders.

1 Like
  1. What kinds of relationships can we represent in a database?
  2. When do we use “One to One” relationships? Give an example from the real world.
  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?
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
  6. What does items_orders table do?

Answers------

    • One to One Relationships
    • One to Many and Many to One Relationships
    • Many to Many Relationships
    • Self Referencing Relationships
      2.If each entry input(like an address) belongs to only one customer, this relationship is “One to One”. as an example when i pay with my atm card… My name, my account number and 1 billing adress.
      3.This is called a “Foreign Key” is used to establish and enforce a link between the data.
      4.When Lazade delivers orders to 2 customers
      5.different customers order different items on different dates with different prices.(correct me if im wrong :stuck_out_tongue: )
      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. One to one
    Many to one, one to many
    Many to many
  2. When we need to define only one thing with the customer. An example is a person and their national security ID.
  3. This is called a “Foreign Key” and it is used for all kinds of database relationships. It is used to ensure referential integrity of the data.
  4. One to many: One customer makes many orders.
    Many to one: A number of items were ordered by one customer.
  5. Many clients made multiple orders.
  6. Its sole purpose is to create a many-to-many relationship between the items and orders.
1 Like
  1. What kinds of relationships can we represent in a database?
    one2one, many2one, one2many, many2many; selfreferencing

  2. When do we use “One to One” relationships? Give an example from the real world.
    Company and its VAT tax 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 Foreing Key to see relation between tables: customers and addresses

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    one order - > many items
    many orders -> one customer

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    many orders connsisting of many items each

  6. What does items_orders table do?
    it shows connections between items and orders ( many 2 many0

1 Like