SQL Relationships - Reading Assignment

  1. The kinds of relationships can we represent in a database includes one to one, one to many, many to many and referencing relationships.
  2. We use “one to one” relationships when running a business especially having to acquire critical information. For example, each employee appears only once in the employee table and each car appears only once in the company cars table.
  3. The reason why the customer_id table is there, is to relate to the other table. Which is known as “Foreign Key” used by all kinds of database relationships.
  4. In an e-commerce example, each customer can have many orders, each order contain many items and each item can have descriptions in many languages.
  5. This applied when an e-commerce had multiple instances in both sides of the relationships such as each order have multiple items and multiple items have many orders.
  6. It does create “Many to Many” relationships between the items and orders
1 Like

1: one to one, one to many, many to many and self referencing relationships
2: is used to connect 2 information related to each other. ex : name and favourite color
3:It is used to associate the name to the specific ID and the specific address.
4: e-commerce : customers and items
5: e-commerce: customrs, items and type of card used to pay
6: items_orders create a many to many relatonship between items and orders

1 Like
  1. one to one
    one to many many to one
    many to many
    self referencing

  2. when an entry or field can only belong to one customer
    person and their sin number.

  3. foriegn keys are used for data base relationships. it helps to maintain the integrity of the data

4.a person who has more than one bank accts.

5.ordering multiple items from an online store.

  1. connects order id with item id
1 Like
  1. Data bases can represent one to one,
    one to many, many to one,
    many to many,
    and self referencing relationships.
  2. A one to one relationship can be customer name and the customer phone number, data only belonging to one customer.
  3. In the article the customer_id column in the customer table represents the primary key (unique data) in that table. Its being used as a unique number to represent the customer which then allows you to match other unique data to the customer with that customer_id only.
  4. Many to one/one to many relationships can be used in affiliate marketing (marketer to customers and customers to products) and other forms that require one person to by attached to many or many attached to one like a club membership (club to members and members to services).
  5. A real world example of many to many could be list of items a customer buys a list of stores near those items are sold at and which products on the list are bought by others near the first customer location. (Customers, products, stores, customer addresses).
  6. Items_orders table represents product (items) data and actual orders that consist of those items some orders containing more then one item in the order.
1 Like
  1. One to One Relationships.
    One to Many and Many to One Relationships.
    Many to Many Relationships.
    Self Referencing Relationships.

  2. A person’s name in relation to bank account number.

  3. customer_id becomes the primary key in the Customer table. The address_id is the foreign key and this can create one-to-many and many-to-one relationships.

  4. A group of people living in one location.

  5. Different people that visited different restaurants.

  6. items_orders table creates many-to-many relationship.

1 Like
  1. One on one, one to many and many to one, many to many, self referencing relationships.
  2. One an entry can belong only to another entry in the table, i.e. address to the customer. Besides an address, a phone number can be an example of a unique attribute that belongs only to one customer.
  3. customer_id is linked to the address_id and it is called “Foreign Key”. Where a field in one table is uniquely linked to a row in the other table.
  4. One to Many can be used when we need to link, for example, a specific country and amount of orders that we need to ship there.
  5. Many to Many will be used, for example, in order to show a relationship between a car that a customer orders and customized parts that he or she wants to have there. Different models of the car can have multiple customized parts.
  6. items_orders table creates Many to Many relationship.
1 Like
  • One to one, one to many, many to one, many to many and self referencing.
  • A unique user and their address.
  • The customer id is a foreign key in the customer table. The customer id relates to the customer table where the customer id is a primary key and shows the record of attributes about that specific customer.
  • A user could speak many languages. This is a one to many relationship. You can have many languages relating to the attribute of human language. This is many to one.
  • Many languages use many letters of the Roman alphabet and there are many Roman letters in the many languages.
  • This table relates an item to an order by the id number of each.
1 Like
  1. One to One Relationships
    One to Many and Many to One Relationships
    Many to Many Relationships
    Self Referencing Relationships

  2. If each address can belong to only one customer, this relationship is “One to One”.

  3. This is called a Foreign Key. This is used for all kinds of database relationships. Its primary role is to enforce referential integrity between data in two tables.

4.For example, when one person makes multiples orders to a store.

  1. Facebook

  2. It links a customer to the right item bought

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 and self referencing relationships.

  2. When do we use “One to One” relationships? Give an example from the real world.
    A table of cars and year of fabrication. This can be a one to one relationship.

  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_id refers to the matching record in the address table.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    We can have cars, colours, year of fabrication and car frame. Two cars can have same color or year of fabrication but each car has only one car frame.

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Same example as above but without car frame. All cars can share colour and year of fabrication.

  6. 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 kind of relationships can we represent in a database?
    • One to One
    • One to Many and Many to One
    • Many to Many
    • Self Referencing

  2. When do we use “One to One” relationships? Give an example form the real world.
    We can use one to one relationships such as when referencing a singular unique user and their information for example Name, address, phone, email.

  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?
    So as only one customer ID will match one customer. It is used to link to other unique data corresponding to that one customer.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    This could be used to match a customer to all the products or services they have used or bought

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    When multiple people are all using and interacting on the same online platform at the same time such as Zoom or Facebook

  6. What does items_orders table do?
    It helps to link together the Items table and the Orders table

1 Like
  1. One to one, One to many, Many to one, Self referencing relationsship.

  2. For example if you want tp cennect a certain person with a certian address.

  3. It’s called Foreign Key and is used for all kinds of database realtionships.

  4. A certain customer order several items on e-commerce website.

  5. A person can put several orders and with several items in every order.

  6. Just to create Many to many relationship.

1 Like
  1. one-to-one, one-to-many, many-to-one, many-to-many, self-referencing-relationships.

  2. Customer - National identity number (in Sweden atleast we have a unique 4-number combination after our birthdate ex 870707-7777) for example ordering something online, this can be cross-checked to verify customers adress for example.

  3. For database-optimization. The database can use the customer_id(foreign key) to remember the customers stored information(adress_id) and faster execute the process of finding data about the specific customer.

  4. A student can attend multiple classes(one-to-many) & a class has many students (many-to-one)

  5. For example many orders of many products.

  6. Creates a many-to-many relationship between items and orders.

1 Like
  • One to One
  • One to Many, Many to One
  • Many to Many
  • Self Referencing
    2.Name and DL number
  1. Every table must have an id that is unique in that table. In the article, it is connected in a so-called foreign key
  2. Credit card statement. One card - many purchases.
  3. Many orders can reference many products
  4. To associate the order with the items inside it.
1 Like
  1. One-to-one, one-to-many or many-to-one, many-to-many, self referencing relationships
  2. One post in a table only relates to one post in another column.
  3. In that case he/she can store adresses in another table, thus referencing the adresses in that table with just a foreign key in the first table. Makes it easier to build relations between many tables.
  4. In a webshop. One customer can have many orders, but an order can only belong to one customer.
  5. Many orders can contain many items.
  6. It records what customer has ordered what items.
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.
    An email can only belong to 1 user

  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?
    Instead of using the full name every time, the author created “customer_id” for easier representation an query

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A customer has many orders, or many orders can belong to a customer

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    An order can have many items, same item can be in many orders

  5. What does items_orders table do?
    relates an item to an order

1 Like
    • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. One customer can only have one mobile number
  2. The customer_id is used in JOIN queries to connect to other tables, such as the address table.
  3. A parent can have many children, and many children have one parent.
  4. A flight can have many passengers, and many passengers can take many flights
  5. items_orders is to record the many to many relationships between items and orders.
1 Like
  1. One to one, one to many(many to one), many to many and self referencing relationships.
  2. Where one entry is only linked to another entry. An example will be the registration of your vehicle.
  3. It creates a relationship between those two entries.
  4. Where a person orders many products or where a specific product is ordered by many customers.
  5. Orders can contain many items and each item can also be in many orders.
  6. This table relates to the order and item by the id assigned to each respectively.
1 Like

1] One to One Relationships
One to Many and Many to One Relationships
Many to Many Relationships
Self Referencing Relationships

2] Where each unique attributes in two separate tables match each other i.e Person <> Birthday

3] This uniquely identifies a record in a table (there could be many records with the same customer name).

4] Many to one = User <> Friends. One to many = Frinds <> restaurant

5] Sals order can have many items, but the unque items can appear in multiple ssales orders

6] Is a link table between orders and items

1 Like

1- Types of relationships:

  • One to One (not really common)
  • One to Many and Many to One
  • Many to Many
  • Self Referencing

2- When one element is related with just one other element. Like country phone prefix and country name i.e. Spain -> +34

3- Customer_id variable is used to uniquely identify each user entry, which in this case has a unique address_id. You would use that address_id to query the full adrees name

4- One to many/Many to One relationship would be (following the example in answer 2) the phones using a given country prefix, all mobile phones in Spain have the same and single prefix +34

5- A Many to Many relationship would be tokens and owners. Many people can own many different tokens, an many different token can be own by many different people

6- Is a Many to Many relation data table, that relates items with orders.

1 Like
  1. We can represent relationships between pieces of data, in the following formats:
    one to one
    one to many, many to one
    many to many
    self-referencing
  2. when a singular piece of data belongs to only one other piece of data, such as one customer having one address, no customers will share the same address
  3. a) this is a Foreign Key and it references another table basically
    b) instead of using customer names, you give each customer a customer_id and you reference that, easier to code
  4. Customer making multiple orders… one to many
  5. Many orders containing many items
  6. This table creates the many-to-many relationship between items and orders.
1 Like