SQL Relationships - Reading Assignment

1.- One to One Relationships - One to Many and Many to One Relationships - Many to Many Relationships - Self Referencing Relationships.

2.- A table for blood donars - Names - address.
3.- It is used to link certain information - “Forgien Key” is the name
4.- Database for medical health records, one person many differrent history data. (One to many)
5.- Google profile data mining comes to mind, all the different information they collect and pin it to you vs other users.
6.- It is used to determine the 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.
    For example, when you have an id card system, the id card number can only belong to one person.

  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 address is unique and belongs only to one customer.
    The address id refers to the matching address is called Foreign Key.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    When you have an online shop with many customers.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    When you have customers with multiple items in one order.

  5. What does items_orders table do?
    Connects the order number with the item number.

1 Like
  1. one-to-one, one-to-many & many-to-one, many-to-many & self referencing relationships.
  2. one-to-one relationships exist when a value of data pertains only to one entity (ex. An address pertaining to an employee within a business’ employee database).
    3.In order to retrieve all information pertaining to an existing entity. It is done by using the ID # or value to access the data within the row it belongs to.
  3. An e-commerce website (such as amazon), that has a wide customer basis, many items to purchase, and a global presence.
  4. An e-commerce website that has the ability to have multiple items in multiple orders to different entity’s within the database.
  5. Creates a “many-to-many” relationship in between the items & orders.
1 Like
  1. What kinds of relationships can we represent in a database?
  • One to one
  • One to many and many to one
  • Many tot many
  • Selfreferencing
  1. When do we use “One to One” relationships? Give an example from the real world.
    One on one relationships is used to connect a unique characteristic to a an object

  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?
    This ID references to another table which corresponds to a certain adress.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A customer can make multiple orders. The orders (many) reference back to one person. An order (one) can also consist of multiple items (may)

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    A class consists of students which can attend different classes from another with different teachers.

  5. What does items_orders table do?
    items_orders shows al the items bought by all customers and show the relationship between a customer_id (referencing back to a certain customer).

1 Like
  1. We can represent:
  • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. One to One relationship is used when one data piece belongs to one record, for example address belongs to customer. Another example is one person has his uniqe credit card number.
  2. Customer id is a Feregin Key that refers to data in it. It shows records when called.
  3. Many to One example - few people can live in one house
    One to Many example - one person can have many phone numbers but one phone number belongs to one person
  4. Many to Many example - one book can relete to different readers and different readers may read multiple books.
  5. It connects items (item id) to orders (order id) in a Many to Many way.
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 a data point can only be referenced to another data point
    each user can only have one SSN, and a SSN can only belong to one 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?
    called a “foreign key.” Used link unique relationships between tables

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    a user can have many hobbies

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    a user can have multiple addresses (several different homes) and an address may belong to multiple users (a family living under one roof.)

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

1 Like
  1. The 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 properties from two tables are only unique to one another. A real world example of this would be someone’s driver’s license number issued to the driver.
  3. This is called a foreign key and is used for linking two tables together.
  4. An example of many to one in the real world could be a rancher branding his/her cattle. Numerous cows with a unique identity that is tied to one entity.
  5. A real world example of many to many could be the university application process. Many different students applying for many different programs and classes.
  6. It’s only function is to create a many to many relationship.
1 Like
  1. What kinds of relationships can we represent in a database?
    1 to 1, 1 to many, many to 1, many to many
  2. When do we use “One to One” relationships? Give an example from the real world.
    when there are unique records. example customer details to passport id
  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 the primary key and can be used to connect to other tables with the same id in them
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship. Friends in facebook
  5. Give an example from the real world when would need to use a “Many to Many” relationship. different customers ordering items from amazon
  6. What does items_orders table do? It connects items and orders
1 Like
  1. Database relationships can include:
  • one to one
  • one to many
  • many to many
  • many to one
  1. A “One to one” relationship in a database would be the information in a customer’s order. For example: Customer_id, Customer_name, Customer_address, Order_id

  2. The customer_id is a foreign key that allows relationships with other data tables. For example customer_id 101 refers to the customer information that is stored on another table.

  3. In an ecommerce environment, a customer could place several orders with multiple different items. The database can reference the customer and list all the items and order information associated with that customer.

  4. As with the previous example, many customers can order many items and many items can be ordered my many customers. In this example, you can also generate a list of items with the customers who purchased that item.

  5. The items_orders table creates a “many to many” relationship between items and orders.

1 Like
  • What kinds of relationships can we represent in a database?
  1. One-to-one, 2) One-to-many, 3) Many-to-many, 4) Self-referencing
  • When do we use “One to One” relationships? Give an example from the real world.

Use a one-to-one relationship when an entity in one table is associated with exactly one entity in another table and this relationship goes both ways. An example is that a customer is associated with only one address and an address is associated (in theory) with only one customer.

  • 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 used as a primary key to link to the address table (where customer_id is a foreign key)

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

Many to one: Many items can be a part of one order; One to Many: One customer can place many orders

  • Give an example from the real world when would need to use a “Many to Many” relationship.
  • What does items_orders table do?

Many to many relationship: There can be many orders and each order is associated with one or more items. The Items_Orders table is a “bridge” between items and orders
[/quote]

1 Like
  1. One to one relationships, One to many and many to one relationships, many to many relationships and self referencing relationships.
  2. We use a one to one relationship when we only need to create a relationship between only two records
  3. It stores an index that can be used to search up the desired record.
  4. An example of a one to many relationship is when you have a site like amazon where you have multible orders per users.
  5. A many to many relationship is when you have a seperate table that contains all of the relationships.
  6. items_orders is a table that creates a many to many relationship.
1 Like
  1. There are many kinds of relationships that we can represent in a database. They are One-to-One, One-to-Many, Many-to-Many, and self-referencing relationships.

  2. We use “One to One” relationships when, for example, one person has only one home address. A single person cannot have more than one mailing address, unless that person is a university student who lives on his campus while taking classes. He returns home mainly on holidays and breaks.

  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 to distinguish one customer from another. Each customer that places an online order has a unique number that identifies him/her.

  4. We would need to use a “Many to One/One to Many” relationship when, for example, a customer has placed more than one order. Each individual order would have a unique ID.

  5. We would need to use a “Many to Many” relationship to determine which items that a customer has ordered belong to which order (i.e. A customer has placed two separate orders on Amazon: one for groceries and another for books and movies. Food items would fit in order 1; the books and movies in order 2.)

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

Thanks!

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.
    These are used when one entry of an attribute can match only one entry of another attribute. An example would be a person and a personal ID or 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 is to make sure that each customer is identified separately and an ID is needed because a person’s name can be the same as someone elses name (so the name cannot be used as a customer identifying factor).
    The FOREIGN KEY constraint is a key used to link two tables together.
    A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY KEY in another table.

The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables.
A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table.
The table with the foreign key is called the child table, and the table with the primary key is called the referenced or parent table.

  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    One person can have many cars registered to their name.
    One voting region can have many voters registered in that area.

  2. Give an example from the real world when would need to use a “Many to Many” relationship.
    A person can register to many classes in a university and a class can have many registered students to it.

  3. What does items_orders table do?
    It organizes a many to many relationship between items and their orders.

1 Like
  1. Types of relationships represented in a database:
  • One to One Relationships
  • One to Many & Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. We use One to One Relationship, i.e. in a customers table when we put some data regarding the customer on a separate table: this can be the social security number, identiy card or driving license. As the social security number can belong to only one customer, this in an One to One Relationship.
    This kind of relationship is not very common.

  2. The customer_id column in the One to One section of the article is used to connect customers & address in such a way that to the customer_id 101 in the customers table can only belong the address 12 Main St., Houston TX 77001. The customer_id 101 is used in order to connect John Doe only to 12 Main St., Houston TX 77001 as a key.

  3. Many to One Relationship example: many students - one teacher
    One to Many Relationship example: one mother - two children.

One to Many & Many to One Relationships is the most commonly used type of relationship.

  1. Many to Many Relationship example:
  • each student can visit several math lectures
  • several math lectures can have several teachers
  • kind of relationship: which student has visited which math lecture with which teacher
  1. Items_orders table links order_ids with item_ids, so specify which orders contain which item.
1 Like
  1. We can represent multiple relationships in a database, such as “one to one”, “one to many and many to one”, “many to many”, and “self referencing”.

  2. The “One to One” relationship is the relation between two items, which only belong to each other. We can see this type of relationship in Sweden where all individuals have a unique personal number that’s only associated with that person.

  3. The customer_id in the customers table is called a “Foreign Key” and refers to the matching record in the customers table. The foreign key is used for all kinds of relationship databases.

  4. An example of a many to one/one to many relationship would be between a person and concert tickets. A person can purchase multiple tickets, the tickets can be translated to multiple languages, but the purchased ticket can only belong to the buyer.

  5. An example of a many to many relationship would be between students and classes. The students can attend multiple classes and the classes include many students.

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

2 Likes
  1. We can represent 5 different relationships in a database:

    • One to One
    • One to Many
    • Many to One
    • Many to Many
    • Self-Referencing
  2. We use one-to-one relationships where each element of the relationship is exclusive to each other. For example, a social security number and a person have a one-to-one relationship. A person is only legal able to have 1 social security number, and that number is unique only to that person.

  3. The author called the customer_id into the table because the analyst should know exactly which customer the data is referencing. As 2 people may have the same name, it’s important to know exactly which customer is being referenced when looking at orders etc. From the customers table, there can be a many-to-one relationship where multiple customers share the same address. They use customer_id to streamline database queries where the database can locate the customer_id and easily find it in the addresses table to select and show the customers’ address. In this case, customer_id would be the primary key in the customer table, and customer_id would be the foreign key in the addresses table.

  4. An example of a many-to-one relationship would be current students pertaining to a particular college. The relationship exists where there are many students going to one college.
    An example of a one-to-many relationship would be where a person lists their devices. For each person, they may have several devices, however each device will only have one owner.

  5. A many to many relationship general consists between friendship/acquaintance circles. For example, a person will have many friends, and each friend will also have many friends.

  6. The items_orders table sits between the orders and items table as a relationship proxy to represent a many to many relationship. An order can have many items and an items can have many orders. As there is only the possibility for 1 item per order, it will reference the items_orders table, which lists each order_id with the corresponding item_id, which references the items table.

2 Likes
  1. One-to-one, one-to-many/many-to-one, many to many (Self referencing)
  2. When one piece of data can only belong to another piece of data like person to their SSN
  3. It is known as a Foreign Key. It allows a piece of data (Customers) in one table to be matched to its corisponding piece of data (addresses) in another table in the database.
  4. Over a college career. A student will have different classes, lectures, times, days but a class schedule will belong to only one student.
  5. When a group of students enter college they can take different classes and the different classes being offered can be taken by different students.
  6. To create a many to many realtionship between items table and orders 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
2)When do we use “One to One” relationships? Give an example from the real world.
We use “One to One” relationships in one relationship between the User table and the email table. Each email can belong to only one user.
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?
Because provides a link between data in two tables.
4)How is it used in order to connect customers to addresses?
Creating a relationship between the customer and the address.
5)Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
Our order history from Amazon is an example of “One to Many.” We are the “one” who have “many” orders connected to our account and vice versa.
6)Give an example from the real world when would need to use a “Many to Many” relationship.
At a college, Student to Classes
7)What does items_orders table do?
Item_orders has the relationship between orders and items.

1 Like
  1. One to One relationships, One to Many and Many to One, Many to Many, Self-Referencing.
  2. When an entry/field can only have one relationship with a user. Ex. A client with their own bank account #.
  3. The customer id is a foreign key and it is used to identify the customer to his address since more than one customer may share the same name.
  4. A “one to many” relationship can refer to a customer with multiple items in an order from Amazon. A “many to one” relation can refer to an individual with multiple bank accounts all belonging to one individuals.
  5. A “many to many” relationship can refer to a college containing hundreds or thousands of students sharing the same classes.
  6. Its purpose is to create a Many to Many relationship between the items and their orders.
1 Like
  1. SQL Relationships:
    One to One
    One to Many and Many to One
    Many to Many
    Self-Referencing
  2. A voters name and his Party is an example of One to one.
    3)The customer_id in the customers table gives the customer a number as a reference along with an Address_ID called a foreign key.
    The Foreign key is the one to one relationship of the customer to the address.
    4)Many to one: Multiple items are made on Amazon and the Delivery guy delivers the items identified to the one Customer.
    One to Many: Customer has multiple orders.
  3. Many to Many: Many values in one table may correspond to many values in another table.
    6)The Items_orders table contains the Order_ID of the customers order in the Order Table: which has the customers ID and total amount paid and the Item_id belonging to the to the Items table:which has the name and the description of the item.
1 Like