SQL Relationships - Reading Assignment

  1. 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
  1. When do we use “One to One” relationships? Give an example from the real world.
    A: We use one to one when connecting one relationship to one object. EX: writing your house address on your driver license

  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?
    A: It is a Foreign Key and it is used for database relationships. It refers to the matching record in the Address table

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A: When you go out to dinner with a group and each person orders different items on the menu

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    A: everyone ordered food but some people placed a to-go order also

  5. What does items_orders table do?
    A: 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?
  • One to one, one to many, many to many and self-referencing relationships.
  1. When do we use “One to One” relationships? Give an example from the real world.

When connecting a relationship between two things. One person has only one social security 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?

You need to have an ID on both ends to connect the tables together correctly. If not, it is not possible to know what costumer has witch address.

  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
  • A family share the same addresses. Many names to one address.
  • One person has many clothes.
  1. Give an example from the real world when would need to use a “Many to Many” relationship.

If more people in the same family share clothes.

  1. What does items_orders table do?

To be possible to use 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.
    Customer’s name and address / contact

  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 make a connection between the ‘customers table’ and the ‘address table.’

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A customer can have multiple addresses or an address can be assigned to multiple customers.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    Multiple items, multiple customers or multiple orders.

  5. What does items_orders table do?
    It is used to create the relationship between the items and orders tables.

1 Like
  1. One-to-One, One-to-Many, Many-to-Many, Self Referencing.
  2. A One-to-One relationship would be used in the instance that a row from one table can only be linked to a single row in another table. An example would be the affiliation between you and your national insurance number
  3. The customer id gives a unique value, that allows the relationship between multiple table to be established. It is called a foreign key. The customer_id is a unique value, which points to a set of details. These details are stored on their own table, so that when you are looking for the occupant of an address, you can take the customer_id and it will return their details (i.e. name, dob, gender, etc)
  4. Many-to-One (vice-versa) relationships are a way to find commonalities between objects or people. An example of this would be your interests or hobbies. Many are bound to have a common interest with you and that creates a relationship that a conversation can be based upon.
  5. The Items_Orders table plays the role of creating a Many-to-Many relationship between 2 values. The item may be unique, the customer may be unique, but the combination of items placed in the order are not unique, therefore finding a way to correlate the similarity between customers based on their orders. This in turn can be used to recommend other items.
1 Like
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. When one unique entry is assigned to one unique person. Like a social security number for an example.

  2. It refers to the matching record in the Address table. This is called a “Foreign Key” and it is used for all kinds of database relationships.

  3. An example could be when a person makes many orders in a webshop.

  4. When one order has many items and when one item is in many other orders.

  5. It links the items in a given order together.

1 Like
  1. The relationships we can represent in a database are: One to One Relationships, One to Many and Many to One Relationships, Many to Many Relationships, Self Referencing Relationships.

  2. We use one to one relationships when one element can relate to only one other element. For example, an email address belongs to only one user.

  3. This is called a Foreign Key, it is used for database relationships, in this case it is used to make a relationship between the customer and the address.

  4. An example from the real world when Many to One/One to Many would be used would be an e-commerce website.

  5. An example from the real world when Many to Many in a student enrollment application, a student may attend many classes and each class can have many students.

  6. 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. An example of a real world a one on one relationship could be between individual people and those individuals’ favorite fruit.

  3. The customer id is a foreign key. One of the main reasons foreign keys are used is because the amount of characters that you use inside each column in a database can be very costly if it is designated as high. This is because you are paying for more storage no matter if you use the characters every time or not. By giving customers a numbered id you can designate a more concrete amount of characters that will be used in that column and thus decrease cost and improve efficiency.

It also ensures integrity when it comes to the data, since you could very easily have more than one “Karen Smith” when people are registering on your website. Having more than one “Karen Smith” could cause confusion when searching for that individual, and thus putting a number to the name is more efficient.

  1. A real world example of one-to-many relationships would be like the other day when I had multiple Amazon orders waiting to be sent to me. Amazon was able to differentiate my orders while also linking them to me personally because the order id’s were connected to my customer id in Amazons database.

  2. A real world example of a many-to-many relationship could be at a restaurant where people who are in different parties are ordering the same dish. Their orders have nothing to actually do with each other separately, but at the end of the day they will each get that same dish. This remains true even if their orders also included other things that the other had not ordered.

  3. The items_orders table is used to “create a many-to-many relationship between the items and the orders.”

1 Like
  1. a) one to one relationship, b) one to many and many to one relationship, c) many to many relationship, d) self referencing relationship
  2. when we want to connect one data to another one data in particular, example of account name and password we use to login to a mBanking account
  3. to make relationship between the stored date can be easily recognizable, it is used by linking one id to another
  4. when we want to check our daily expenditure, and doing so by put one day id to the list of purchase done in that day
  5. when we want to give several type of voucher to several event participants id
1 Like

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

When do we use “One to One” relationships? Give an example from the real world.
You would use when one piece of data can be linked to only one other piece of data, so a student and main residence address could be split one to one. I think in a lot of cases such data would be normalised and stored in one table, but having a two tables does make the relationship optional.

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, and is used to uniquely identify a customer. The customer table also has an address_id column, which also appears in the address table. The customer has a reference to a unique address, and the relationship allows data from two tables to be joined.

Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
Many order items could refer to one product. One customer could have many orders.

Give an example from the real world when would need to use a “Many to Many” relationship.
Books and Authors. A book could have mulitple authors, and additionally some of the authors could have penned multiple books.

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

1 Like
  1. one to one
    one to many
    many to one
    many to many
    self referencing
  2. a)this is used, if there is always exactly one reference record in the other table, as in this one.
    b) a customer has one address for delivery /
    a user has one date-of-birth
  3. the customer_id is the primary-key of the customers table. In other tables the reference to the customer_id is the foreign key. Thats how relations are estabilished: in other tables, where this customer_id is used (as a foreign-key), i.e. in an order.
    4)items in an order = n:1
    user has several friends = 1:n
    5)a user belongs to several community-groups
    a community-group contains several users
  4. it lists the items that figure in orders, so you could put together delivery-papers or invoices
1 Like
  1. One to One Relationships, One to Many and Many to One Relationships, Many to Many Relationships, Self-Referencing Relationships.
  2. When an entity belongs to only one output, this relationship is “One to One.” A real-world example of One to One relationship is Social Insurance Number.
  3. The column customer_id is created to form a unique identifier and to minimize the data so that the program code can be simplified. When two fields from different tables are connected, it is called a “Foreign Key.” It is used for all kinds of database relationships.
  4. A real-world example of One to Many relationships would be an email address. One user can have multiple email addresses.
  5. The classic example of Many to Many relationships is e-commerce.
  6. The Items_Orders table has only one purpose, which 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 one, many to many, self referencing
2 - one person to one social security number
3 - its used as a indexing “key”, thats the “key” to refer to possible values in another table
4 - car owners to cars, cars to car parts
5 - eg. dating site -
guy(s) [table]; girl(s) [table]; Like(s) [table]
guy1 ->like1->girl1
guy1 -> like2->girl2 & girl3
guy2 -> like3->girl1
guy3 -like4 -> girl2 & girl4

1 Like

6 - creates the relationship between the tables (using the keys)

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

  • When do we use “One to One” relationships? Give an example from the real world.
    When individual pieces of information are linked together like name and 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?
    In real life customers can place multiple orders and this can create a long list with the same name.
    Linking the name of the customer to a unique number, boils the long list down to numbers that represent a bundle of the customers name. This allows the database to serve the results more efficient. This is also known as a Foregin key.

  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many items can be bought by one customer and many customers could buy one item.

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    A referral link is one of these examples, something that I share with my friends, and they could share as well. Please use this link if you are not familiar with crypto.com :wink: https://platinum.crypto.com/r/sma7au68t3

  • What does items_orders table do?
    It links the items to the orders that are created (many to many relationships)

1 Like

[quote=“ivan, post:1, topic:6431”]

  • 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
    selfreferencing relationships
  • When do we use “One to One” relationships? Give an example from the real world.
    When a unique item matches only one unique item of another table. For example One person has only one 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?
    There is only one client attributed with one customer_id. This matches with only one addres_id.
  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    One person makes multiple orders.
  • Give an example from the real world when would need to use a “Many to Many” relationship.
    One person makes multiple orders of various items.
  • What does items_orders table do?[/quote]
    It creates many to many relationships between orders and items.
1 Like
  1. One to One Relationships; One to Many and Many to One Relationships; Many to Many Relationships; Self Referencing Relationships.

  2. We use “One to One” relationship when one value belongs to only one customer. An example is the name associated to the social security number.

  3. It is called a “Foreign Key” and it is used for all kinds of database relationships.It makes sure referential integrity of the data.

  4. An example of “Many to One/One to Many” relationship is when I shop online, I can buy many items that are belonging only to me.

  5. An example of “Many to Many” relationship is when many students are enrolled in many classes and the classes have many students.

  6. The items_orders table has the purpose 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 “key” & “value” are typically singular. A building has 1 location, so it generally has 1 street 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?
    customer_id is the “unique” id assigned to each customer of the table. The Customers table contains the foreign key column address_id linking it to 1 address in the Addresses table. NOTE: In a normalized database, there would be an AddressRelation table instead of holding the fkey in the customer table, foreign keys could be customer, address, & shippingAddress (if this scenario was needed)
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    My family has 1 dog, the dog belongs to many family members
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    A building may contain many apartments, each apartment may contain many rooms.
  6. What does items_orders table do?
    Relates each order to their respective order items, and each item to the orders “requesting” it.
1 Like
  1. 1-to-1, 1-to-Many, Many-to-Many, self referencing
  2. 1 entry from one table is liked to 1 in another table. 1-to-1 is rare. One Person has one fingerprint
  3. The id functions as a key, which allows him to connect the tables. Both tables contain the id and therefore its possible to match them.
  4. One customer can have several orders; One order can only have one customer
  5. One order can contain several products. One Product can be part of several orders.
  6. Linking items to orders —> which items did an order contain
1 Like

What kinds of relationships can we represent in a database?
One to one
One to many
Many to many
Self referencing

When do we use “One to One” relationships? Give an example from the real world.
One person can have one birth date

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 foreign key, which is referenced in the address table, though defined in the customers table

Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
Many people may have the one birthdate
One date may be a value cited in a table of events

Give an example from the real world when would need to use a “Many to Many” relationship.
Dates may connect to multiple events
Events may connect to multiple days

What does items_orders table do?
It lists the type of items included in each order

1 Like
  1. One to one, one to many, many to one, many to many, self reference
  2. 1 to 1 is used when you want to reference one unique field that is related to another unique field. E.g… customer ID to customer name
  3. Customer ID is unique field created as the main key that identifies all the fields related to that customer record. This includes the address field which you query specifically when you know the customer ID
  4. Many to one - multiple members of one unique team
    One to Many - one customer order includes multiple items with that order.
  5. Many to many - multiple customers order same multiple items
  6. M2m Relationship between all items and all orders
1 Like