SQL Relationships - Reading Assignment

  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. One address for each 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?. The customer_id is the foreign key 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 person purchases many items from a store / one store fills many orders of items purchased by customers.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Facebook, many people connected to many people and many groups, etc.

  6. What does items_orders table do? Connects the order_id to the item_id.

1 Like
  1. One to one, one to many/many to one, many to many.
  2. Data only applies to one entry - Person and their social security number.
  3. Customer_id is a primary key used to query the data base using the Join function.
  4. Referrals - people I have referred, people who have been referred by someone.
  5. Facebook friends relationships.
  6. It is a many to many relationship table between items and orders.
1 Like
    • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. in lifelong absolute monogamy ‘spouse’ is 1-1
  2. customers could have the same name or address but not ids
  3. in harems, where the man has many women but not vice-versa
  4. modern egalitarian polyamory
  5. it creates a many-many relationship
1 Like
  1. A database is a collection of rows and columns with data logged in each unit that crosses. The relationships are links between these tables in multiple ways.

One to One
Many to One
Many to Many

  1. A one to one relationship is when you have one item from one table linked to a specific item in another table only.

example:

customer Id is linked specifically to customer address.

one customer Id is linked to one customer address.

  1. The customer table will have a list of customers and their corresponding Ids. Each customer has a specific unique Id and it is not possible or correct for two customers to share the same Id.

Hence each Id will have a specific address linked to it. So in the database whenever the customers Id is brought up the address attached to it is also brought up.

  1. Many to One:

multiple orders for the same item = many people ordering same pizza

One to Many:

One order for multiple items =. One order of Pizza with multiple toppings

  1. Many to many:

Multiple orders for multiple items = multiple pizzas each having a different set of toppings for different clients

  1. Its purpose is to create a many to many relationship between the items on the order page.
1 Like
  1. Types of relationships represented in a database: one-to-one; one-to-many; many-to-many.
  2. One-to-one relationship example: one person to one address.
  3. The customer ID references the person attached to an address, if only the address is present in the other table. The customer ID in this case is a “foreign key” that can be used to establish a relationship to another record.
  4. A many-to-one relationship example is when you have many people traveling from different cities to one big conference in Vegas. And one-to-many would be when all the individuals leave Vegas to return home.
  5. A many-to-many real world example is when a travel agent is making arrangements for many different couples planning their dream vacation. Everybody is coming from someplace different, and everybody is going to someplace different, although there may be some cross-over, if several couples go to Hawaii, for instance.
  6. An items-orders table creates a many-to-many relationship among 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.
    When the usecase requires that you store one item in table A, linked to another item and only that specific item in table B. For example a student that has a student ID, the information can be stored in table a while the student ID (specific for only that student) is stored in table B.
  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 references to another table where the customer address is stored, this way you create a Foreign Key, with this you create the exact data structure and is indexed automatically.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many to one: student(s) (many) that work on the same project (one)
    One to many: Customer (one) can have multiple sales orders (many)
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    a student that attends a class, the class (many) will have many students, and the students will attend more classes (many)
  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
  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.
    Inputing a customer and their address into a table. Possibly for storing that on a website.
  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?
    That’s referred to as a “Foreign Key”. It pulls data from the customer_id to create an address_id and is a common tool in database relationships.
  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    If a customer wants to buy toothpaste along with other items, we need a table that represents one (customer) being able to buy many (items). Also vice versa, many customers buying one item.
  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    Many customers are buying many items, some overlapping, i.e. toothpaste is going to multiple customers along with other items in their full order.
  5. What does items_orders table do?
    It shows us the full relationship between items and customers. It shows us the “Many to Many” relationship.
1 Like
  • What kinds of relationships can we represent in a database?
    One to many, many to many, many to one and self referencing
  • When do we use “One to One” relationships? Give an example from the real world.
    My address and my phone 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? This a foreign key. It is how the customer and address table relet to each other
  • **Give an example from the real world when would need to use a “Many to One/One to Many” relationship.**Customer may have one car but the car has many parts so all of the parts belong to one car
  • Give an example from the real world when would need to use a “Many to Many” relationship.

A dealership has many cars that are purchased by many customers

  • What does items_orders table do?
    It shows all of the items for each order
  • What kinds of relationships can we represent in a database?
    One to one, one to many, many to one.

  • When do we use “One to One” relationships? Give an example from the real world.
    You have a Smart contract with a Blockchain address.

  • 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 unique identifier of the customer accross all the database. We can then use this id to link a whole customer with other entries, thus building strong data relationships.

  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many to one : An application has many developpers. Each programmer also code many applications.

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    A car has many part Ids. Each of these parts can be used for many cars.

  • What does items_orders table do?
    It is a table that links two other tables with a Many to Many relationship. So that table don’t contain “pure data”, but only defines relations.

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

  • One to one Relationships
  • One to many & 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.
When an Information can belong only to one user for example: A user can have only one 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 Customer_id can be used in other tables in order to reference to the customer table and its information regarding the customer. In all the Non Costumer tables, it is used as foreign key for creating relationships.

4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
In E-commerce this is the most used Relational representation, since one customer can have many orders with many items while at the same time one item can be represented in many orders of different customers.

5. Give an example from the real world when would need to use a “Many to Many” relationship.
A good example is the Database of Facebook which stores the friends of my friends and and the friends of their friends.

6. What does items_orders table do?
It creates a Many to many Relationship.

1 Like
  1. What kinds of relationships can we represent in a database? one-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. when an attribute is unique to one other attribute. Like a relationship between an individual and their social security number. everyone has their own unique 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? in the example, each customer has a unique address and has a one to one relationship between their name and their address.
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship. People who own more than one car or property, that would be one to many. People who go to the same gym would be many to one.
  5. Give an example from the real world when would need to use a “Many to Many” relationship. Business supplies ordered by multiple businesses would create a many to many relationship
  6. What does items_orders table do? creates a many to many relationship between items and order.
1 Like
  1. We can represent the one to one, one to many, many to one, many to many, self-referencing
  2. in one to one relationships, defined by a foreign key, we can use the example of a user and his username.
  3. customer_id was create to be used as a foreign key in customers table to connect for example to the addresses customers table. that is an example of one to many
  4. An example of many to one can be to have “many orders from different clients or same clients to one item”. One to many relationship can be the client_id wich can be used, for table orders,table users
  5. many to many can be many teachers to many classes to many students
  6. it can record, track the information between items and orders tables.
1 Like

1: A database can represent relationships like one to one, one to many, many to one,many to many as well as self referencing relationships.

2: We use one to one relationships when a customer value belongs to just the one customer only.

2a:An real world example is a customers name

3: Customer iD in the table ensures connection between two tables of info on the same i customer.

4:One to many examples is the one customer with many orders to their name.

5: Many to many example is customer has one order with many items in that one order.

6: Items_orders tables record the the relationship between the many items to the many orders, the one customer has.

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? Give an example from the real world.
	○ Patient -> 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 can be used as a foreign key to link pieces of information together from different tables
4. Give an example from the real world when would need to use a "Many to One/One to Many" relationship.
	○ Patient -> Medications
5. Give an example from the real world when would need to use a "Many to Many" relationship.
	○ Items <-> orders   Each item could be in multiple orders. Each order could have multiple items.
6. What does items_orders table do?
	○creates a "Many to Many" relationship between the items and the orders.
1 Like
  1. One to One, One to Many and Many to One, Many to Many & Self-referencing relationships.

  2. When one value can only be linked to a particular entry which can not be linked to any other value or entry.
    An example of this is the state issued ID number of the citizen of a country.

  3. To reference the customers with individual numbers and establish relationships without the need to write the customers’ names on each table they are referenced in later on, so the "customer_id"s replace the customers’ names on the tables to come. Each of those numbers in the example are foreign keys that are assigned to each particular customer.

  4. Clients are registered at a private Pilates studio where they can have zero, one, or more appointments.

  5. Individuals are registered at a surgery where they have zero, one, or more appointments with one or more medical practitioners.

  6. It creates a “Many to Many” relationship between the items and the orders on a data base.

1 Like
  1. One to One Relationships
    One to Many and Many to One Relationships
    Many to Many Relationships
    Self Referencing Relationships
  2. These relationships are used for unique relations where there is one input one output.The mail man delivering mail to your unique home address.
  3. It is a foreign key given to each user to describe a relationship to specific data not shown on the table that relates to them only.
  4. A unit of supply being distributed to many unique addresses.
  5. Unique people ordering various foods at a restaurant. Some of the customers will be receiving the same food, however, the food goes to their unique table; and also may include food items that other tables didn’t order.
  6. It creates a many to many relationship between clients and orders.
2 Likes

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

One to one, one to many and 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.

The customer and his 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?

It’s the key that connects customer to address.

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

When you have more customers that are related to specific item that connects them.

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

I want to use the restaurant that none of my friends did.

6.What does items_orders table do?

It creates many to many relationship.

1 Like
  1. Different types of relationships in databases are: one to one, one to many, many to one, many to many, self-referencing relation.

  2. When getting information from the IRS on an individual.

  3. Each customer has it’s own ID that is matched to the addresses id of the addressed table.

  4. Many to many relationship can be used for employer/employees. An employer has many employees but each employees only has one employer.

  5. It could be a list of classes and students at a school or a costumer at a fast food restaurant.

  6. An Items_order sets and establishes many to many connections and relationships between items and orders.

1 Like
  1. One on One Relasionship / One to Many and Many to one Relationship / Many to Many Relationship / Self Referencing Relationship

  2. it’s use when one items or data can be link only to another data.
    person / telephone number

  3. it refer to a matching record using Foreign Key

4.on a website they need a different foreign price for any article in sale

  1. Amazon, (customers, adresses, different type of orders)

  2. refer a column in another table

1 Like
  1. What kinds of relationships can we represent in a database?
    There are four types: 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.
    When you are storing a person and their data so a name and their address or a name and their phone number sort of like contacts in a phone book but less sophisticated
  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 identifies the underlying data as it is used as a matching record for the table to be identified. This is called a “foreign key”
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    One to many is like the contacts above where its one person to their phone number and their address and their birthdate. Many to one is a situation where it’s reversed, the phone number, and address and birthdate are all mapped to one person (the contact in this case)
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    When mapping customer orders to items ordered. some customers can order the same items and some items could be ordered by multiple customers
  6. What does items_orders table do? It servers to refer to a position in another table and pass on the data or information needed
1 Like