SQL Relationships - Reading Assignment

  • 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 relationship to establish an association between two pieces of information. A real-life example could be a person and their clothing size.

  2. The customer id is a foreign key and its used to associate the relationship between customer and their address.

  3. A person can order a meal which can have many ingredients in it, yet these ingredients can cause various chemical reactions in an individual, therefore one may refrain from having certain ingredients in their order.

  4. I suppose that many to many relationships could be the example of students signing up for classes and ordering the required textbooks for said classes.

  5. It helps to display a visual representation of the many to many relationships (items and orders).

2 Likes
  1. Here are the forms of table joins

    • One to One Relationships
    • One to Many and Many to One Relationships
    • Many to Many Relationships
    • Self-Referencing Relationships
  2. A. When the Primary Key and Foreign key only have one instance and are unique in each table
    B. A person only has one primary residence (Person Name and Residence)

  3. A. It is the Primary Key used to identify each unique customer instead of using the customer name.
    B. Each customer has an address_id in the customer table and is used as a foreign key that is utilized as the common link between the Customer table and Address table. The foreign key will will match the Primary Key on the Address table.

  4. An order table will have an Order ID as the primary key in the Order table but each order will reference one customer. The customer will be the foreign ID on the Order tab and will be a match to the primary key on the Customer table. The customer can have multiple orders so the customer ID may show up multiple times on the Order table but only once on the Customer table.

  5. When you go to a restaurant and order food the check number is attached to each item sold so the restaurant knows what check to charge the food onto.

  6. The Items_Ordrs table shows the relationships between the order (check #) and the items that were ordered.

2 Likes

1:One to One , One too Many Many to one , Many to Many and Self referencing Relationsips
2:When only relationship can be had for example Name and driver license number
3: It identifies this as a table that can be referenced to another table IE customers to orders
4 where a customer may have multiple orders but an order can only belong to one customer
5:i It links the Items table to the order table

2 Likes

I read the full article :joy:.

  1. One to one, one to many & many to one, Many to many and Self Referencing relationships

  2. One customer to one address associated only with him. Like a database for an address book.

  3. It is Known as a foreign key. That is the link between the relationship of the Name and The Address

  4. Like an Exchange of a coin you’ve traded. Many orders you’ve placed of that coin bowling only to you. But that same coin has different orders from different people.

  5. A parts department would make use of many to many relationship regarding who bought what parts for such car. They have a table consisting of stock of item bought another section saying stock left for the retailer and also data linked to the Custer with the address and possible trade number.

  6. Items orders is for creating a many to many relationship between the items and the order’s.

2 Likes
  1. One to one. One to many. Many to many. Many to one. Self referencing.
  2. One to one relationships are when one item can only belong to another item. In the example given, one customer can only have one address, but this is not often the case. A better example is a table of citizens with their own social security number. Each citizen can only have one. Another example is a table of marriages. Each person can only be married to one other person.
  3. It’s called a Foreign Key and is used in many relationship tables to refer back to another column and row. I imagine it makes setting up tables easier. A number or ID or Foreign Key is easier to manage?
  4. Many to one would likely be used extensively in Amazon as would one to many. For example, I might buy a toothbrush and toothpaste from Amazon. That’s many to one. Me, the one customer, buying many items. If many customers buy the same toothpaste this could be a one to many where the one toothpaste is bought by many customers.
  5. Perhaps Facebook would use such a table. Maybe there are many people who belong to many similar groups?
  6. It’s single purpose is to create a many to many relationship 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 many
    self referencing

  2. When do we use “One to One” relationships? Give an example from the real world.
    if each value can only belong to one entity. for instance one delivery address can only belong to 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?
    it is given a specific value that ties to the row of the address table where the values match.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Where a customer can have multiple orders linked to same user ID. for instance when you buy online and you have placed 2 orders and it reference back to you.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    when may items are linked to a single order in your shopping cart

  6. What does items_orders table do?
    to create a many-to-many relationship between items and the orders

1 Like

1.- 1 to 1, 1 to many, many to 1, many to many and self referencing relationships
2.- when we had an unique relations between two tables, meaning one record of table A had a unique relation to a record of table B.
For example, when a user register to a website, by his e-mail. If the information was stored in separate entities.
3.- The customer_id is the primary_key which identifies the customer. From that table, you can obtain the address_id which is the foreign key to the address table, where you can fetch the address of the customer
4.- When you model the user, you have multiple users for one country (many to one).
And one user could multiple phones (one to many)
5.- Students and courses assigned in the semester (many to many)
6.- Creates a many to many relationship between items and orders

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

  2. When one record in a table is associated with only one record in another table. Example User Name to Social Security Number

  3. Customer_ID is a unique key used to relate a record in one table (Customers) to a record in another Table (Addresses). This tether ensures the association between correct Customer to Address.

  4. A company with multiple geographical locations, franchise for example. One Customer Name will be associated with Many Addresses.

  5. Orders, many orders will have many items.

  6. This tables creates 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, one to many, many to many
  1. When do we use “One to One” relationships? Give an example from the real world.
  • I pick one restaurant to go to for lunch today
  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?
  • this allows the user to track their customer by the customer id instead of looking them up by their name. It allows the user to have a more concise table and it creates a one to one relation.
  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
  • Many people may pick one restaurant to go to for lunch, and one person may have many options to choose from for their lunch at that one restaurant.
  1. Give an example from the real world when would need to use a “Many to Many” relationship.
  • Many people have many options to choose from for their lunch, and those options or choices of lunches may have more options to choose, ex. sides, extra veggies, dressings, gluten-free…
  1. What does items_orders table do?
  • to create many to many relations
1 Like
  1. One to One, One to Many, Many to Many Relationships

  2. A unique user and their age.

  3. This links two tables together and is a way to organize information.

  4. When a customer makes multiple orders on a specific item.

  5. Customers orders the same item and each customer gets a uniqe order id.

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

1 Like

What kinds of relationships can we represent in a database?
A: * One to One Relationships

  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships

When do we use “One to One” relationships? Give an example from the real world.
A: If each address can belong to only one customer, this relationship is “One to One”. Example: seats on an airplane.

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?
A: Because it identifies which specific customer at that address. There can be more than one customer per address.
How is it used in order to connect customers to addresses? With the address id #.

Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
A: Orders from an e-commerce website where many orders and many items per order can be attributed to a single customer.

Give an example from the real world when would need to use a “Many to Many” relationship.
A: An e-commerce order that contains multiple items, items that may be in multiple orders.

What does items_orders table do?
A: 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
2.When do we use “One to One” relationships? Give an example from the real world.
users,user id,user name,user age
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 order to create a reletationships between customers and thier data

4.Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
Many items ordered by one customer ,one customer ordered many items
5.Give an example from the real world when would need to use a “Many to Many” relationship.
A social platform with many groups with many users
6.What does items_orders table do?
Records all orders and details.It make easy to track users orders by keys:customer_id ;order id

1 Like
  1. one to one, one to many, many to one, many to many and self referencing
  2. a unique user and their adress
  3. foreign Keys are used for all kinds of database relationships. It is used to ensure referential integrity of the data.
  4. a list of students and a list of classes, where a class can contain many students and a student may be enrolled in many classes.
  5. link the customer to the right bill
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 relationship is between a record in a table and a record in a different table exclusively.
    e.g. A student and their student ID.
  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?
  • In the customers table, the customer ID field is the primary key. In the addresses table, the customer ID field is a foreign key. This relationship returns related records when the value in the customer ID field in the addresses table is the same as the customer ID field in the customers table.
  1. Give an example from the real world when you would need to use a “Many to One/One to Many” relationship.
  • It would be used for a patient and the patient’s medical history.
  1. Give an example from the real world when would need to use a “Many to Many” relationship.
  • When Dealing with customers and items.
  1. What does items_orders table do?
  • 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?
There are several types of database relationships - One to One Relationships, One to Many and Many to One Relationships, Many to Many Relationships, Self Referencing Relationships and more.

  1. When do we use “One to One” relationships? Give an example from the real world.
    When phone number belongs to only one person. There are no other people with same 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?
    In this case one address refers to only one customer.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    When we are in restaurant and everybody wants something to eat. Everyone makes his own order with different meals.For example I want soup and main meal and dessert, other guy wants different soup, same meal and no dessert,…

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    When we order food from more restaurants so we get different sort of meals. Some orders are same, some are little different and others are completely different.

  5. What does items_orders table do?
    Its purpose is to create a “Many to Many” relationship between the items and the orders.

1 Like
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. If you need you need to input address data for a given customer and the address can only belong to this specific customer.

3.The address ID is used as a unique identifier know as a “foreign key” it is used to create different types of database relationships. The Address ID is shown in the customer table which can be used to reference the Address table to find the customers unique address.

  1. Soccer athetes belong to one team. One team has many fans.

  2. The olympics has many sports that in turn has many different athletes.

  3. 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, one to many, many to many and self-referencing relationships
  2. when we want to link each row in one database table to one and only one other row in another table;
    an example would be for instance an individual and his tax number (depending on country probably), each is individual and one cannot have more
  3. each customer is assigned his own customer_id which in turn is accompanied by the address_id, the address_id is linked one-to-one in another table which has address information
  4. when for instance we have a case of one person doing multiple tasks/transactions, maybe like clocking in to work, then clocking out, it would use the same customer_id for both, but link with appropriate data to many other tables
  5. school roster and attendees for certain lectures, each individual students has different classes he takes, some take the same classes 4/5 times, but some overlap only certain times; each classes can also have additional data that changes, like time, location (which classroom),…
  6. it creates a many-to-many relationship between the orders and the items tables
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.

Data base of married couples. (Assuming we don’t have a many wives society). Data base of people’s birthday and place. Data base of people’s social security or tax reference or bank account. One person can only have one DOB or SS 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?

There is a table with links customer ids to their name and address. The id is then shorthand for that customer and is used to reference them in connection with orders.

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

Twitter: I as one user have many followers. I follow many people. One person can own multiple homes or properties hence one to many relationships. One gym can have hundreds of members, hence one to many.

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

An open relationship? I have lots of partners and my boyfriend has lots of partners…sorry that example is rubbish, I should think of something better. Facebook friendships are many to many. I guess opinion polls would contain many to many relationships ie. People may each chose different options or answers to each question. However, instead of asking what person A thinks are the top three problems facing his country, you can also ask that question as, How many people said Covid was the number one problem facing the country? Hence many to many.

  • What does items_orders table do?

Keep track of many to many relationships ie multiple orders can contain many of the same items as well as different items. Ie order #1 may contain items, A,B,C. Order #2 contains items C, D, E. So C has a relationship with two different orders, Order #1 and #2 have a relationship with three items each.

Keeps track
[/quote]

In

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

One to one

One to many and many to one

Many to many

Self referencing

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

Where each individual item in table 1 can belong to only one item in table 2 and vice versa. Eg. Motor Registration database with tables “Car ID” and “Registration Number” where each car can only have 1 registration 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?

Having the “customer id” identifies that each customer will be unique ie. In the event 2 customers have the same name, they will be differentiated by their allocated unique “customer id”. Connecting each customer to one address is done by connect 1 customer id to each “address id”

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

Stock trading platform where tables are: “Completed Trades” and “Customer” where each customer can have zero, one or multiple trades but each trade can belong to only 1 customer

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

A betting website database with tables of “betting transactions” and “selections” where each betting transaction can contain multiple selections and each “selection” can be in multiple “betting transactions”

  1. What does items_orders table do?

To create a many to many relationship between the xxx ID column of table 1 and the yyy ID column of table 2.

1 Like
  • What kinds of relationships can we represent in a database?
    1.One to One
    2.One to Many
    3.Many to One
    4.Many to Many
    5.Self Referencing

  • When do we use “One to One” relationships? Give an example from the real world.
    When use a One to One relationships when various entities on a table is associated to one single user.
    An example will be a customer that order just one car from a car manufacturing 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?
    This is a unique identifier for each customer present on the database.And it is use to connect the customers to it’s unique address provided we have another address table to simplify search or referencing.

  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many to One/One to Many
    An example will be a customer that has many postal address e.g Home,Work,Correspondence and Oversea Address where they want their Mail or Orders to be sent to.OR a company that has many hired car of different models

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    Group of Travellers having many transits on different route before they reach there destination.

  • What does items_orders table do?
    It is a form of Many to Many relationships that indicates or track different/same items ordered by individual or different customers.

1 Like