SQL Relationships - Reading Assignment

    • One to One Relationships
  • One to Many and Many to One Relationships
  • Many to Many Relationships
  • Self Referencing Relationships
  1. When there is a only one relationship assiocated to the entry, A persons name to drive license number
  2. Foreign Keys role to make sure when tables are queried related data stays the same
  3. a single individual and crypto wallets
  4. not 100% on this but hockey scramble that there are many players that get randomly chosen to many different teams, if that doesnt work pretty sure amazon store is an example
  5. 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, One to Many, Many to one, and many to many.

  2. When do we use “One to One” relationships? Give an example from the real world.
    when a piece of information is associated with 1 individual or 1 subject.
    Phone numbers for family members stored on your device.

  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 a foreign key assigned to each customer so it can be used to create the relationships between a customer and other tables such as Addresses and Order while making sure these relationships are accurate because there could be more than one customer with the same name. The customer_id appears in the Addresses table to connect each unique customer account to their address.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    You could use your bank statement with the number of funds used on certain days.

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

  6. What does the items_orders table do?
    creates “many to many” relationships between order_id and item_id

2 Likes

One to One Relationships
One to Many
Many to One Relationships
Many to Many Relationships
Self-Referencing Relationships

one-to-one – A company and company ID

The Customer ID is defined in the customer table, so the info doesn’t need to be repeated in other tables. They just reference the ID, and all of the fields can be referenced for the customer

Many to one
One to many example would be an address and the multiple people with that address. Many to one would be orders for a single person

Many to Many example is for store transactions, where many people buy a product, or many products go to a person

The items_orders creates the many to many for 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

  2. When do we use “One to One” relationships? Give an example from the real world.
    If each information entered in all tables (that is not a relationship table) has a unique ID in that respective table. For example, a telephone directory database will have each users assigned a unique 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?
    The customer_id column can be used to easily query (or view: in SQL terms) the database for any information in the customer table such as the entries in the customer_name column. The customer_id column can be written in a relationship table (arbitrarily named addresses) as well, which makes it foreign, along with a column that can be arbitrarily named as address, having entries of each customer’s address. These steps taken connect each customer’s address in the relationship table to the respective entries in the customer table such as the customer_name. The entries of the customer_id are connectors for the entries in the customer_name and address columns.

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Many blockchain transaction IDs appended to a block/A block having many appended transaction IDs

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    Many freelancers working for many companies. Many companies employing many freelancers

  6. What does items_orders table do?
    It is relationship table that uses the entries of order_id and item_id to connect the data of the orders table and items table. It connects items purchase info such as name, description to the customer’s info such as date of the order, and the amount. This creates a Many to Many relationship

1 Like
  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
  1. When do we use “One to One” relationships? Give an example from the real world.
    One to One relationships are used when one record is exclusively linked to another record. An example is the identification number of cattle on a farm – every farm animal has a unique number that is only associated with that particular animal and no other.

  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 is unique to every customer. Under the assumption that only one customer can order from this address, the addresses can be stored in a separate table, and be replaced with an address_id in the current table. As the address_id and customer_id are unique to the customer, a one-to-one relationship is formed. When a new order is created, the customer’s address can quickly be identified it has been tied to the customer’s customer_id.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    The relationship between accounts and characters in an MMORPG, assuming one account can create multiple characters. One account can be associated with zero, one, or multiple characters. However, characters can only be associated with one account.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    Example: Many companies require many different types of licenses to operate in an industry.

  5. What does items_orders table do?
    It creates “Many to Many” relationships between items and orders.

2 Likes
  1. What kinds of relationships can we represent in a database?
    1-1
    1-n
    n-1
    n-n
    self refrencing

  2. When do we use “One to One” relationships? Give an example from the real world.
    for example when 1 customer can only have one address ( or when 1 address can only have 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?
    as a (foreign) key. to reference a column in another table

  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    many customers can order one item

  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    where each order can contain multiple items. And each item can also be in multiple orders.

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

2 Likes
  • One-to-one, one-to-many, many-to-one, many-to-many, self referencing.
  • When a field only belongs to one other field; a citizen name and his passport number
  • To enforce referential integrity, It is a field in a table that uniquely identifies a row in another table
  • A student and different classes IDs
  • Many students have many professors (they could have the same profs, or not).
  • Creating a relationship between items and orders (many-to-many)
1 Like
  1. One-To-One, One-To-Many, Many-to-Many, Self-Referencing

  2. One to one relation ship means an entity in a table can reference a different entity in a different table. For example, Social Security is having a one-to-one relation with SSN and to the person.

  3. customer_id is the primary key to identify a unique customer in customer table. Corresponding to the customer_id, there is a foreign key present in the table called address_id which can be used to refer the address in the address table.

  4. Many to one: A group students can have only one class teacher.
    One to many: The president have several subordinates under him.

  5. Take the case of a university, where many courses are taught by many professors.

  6. It maintains the record of orders and the corresponding items added in that order.

1 Like
  1. One to One Relationships, One to Many and Many to One Relationships, Many to Many Relationships and Self Referencing Relationships.
    2.When the relationship is to one specific entity, eg. the age of a client or the address of a client.
    3.The customer_id is the unique identification number of a particular customer, The customer-id attaches to a specific customer, the database will query the customer and locate his address in the row containing the customer_id.
  2. Individuals can shop at amazon.com there are many items that an individual can purchase and these items can be purchased by many people, but each order can only be made for one person.
    5 Many .Individuals can shop at amazon.com there are many items that can purchased and these items can be purchased by many people,
    6.To connect many items to many people.
2 Likes
  1. One to one relationships, one to many and many to one relationships, many to may relationships, and self referencing relationships.
  2. When a unique piece of data relates specially to data in another table. A real world example would be a individual and their driver license number.
  3. This is a foreign key and is used to retrieve data for a specific item in many instances. It connects customers to addresses by retrieving the information from the customer_id and consolidating it together.
  4. Ecommerce like Amazon. Where you may have mulitple products being purchase in one order.
  5. An example of Many to Many relationship would be a pool where multiple people are putting money to purchase one or multiple items together and the items being distributed.
  6. It connects the individual item to specific total list.
1 Like

1.- one to one, one to many, many to one, many to many and self-referencig relationaships.
2a.- even though it is unusual, it ocurs when there is a direct correlation of data in two diffent tables.
2b.- People to its social security number.
3a.- The Foreign key serves as a link between two tables.
3b.- Through the connector of the two tables or Customer_ID, where both each customer and its adress share the Customer_ID attribute.
4.- One to many; one Customer might have several orders.
5.- Clothing in many colors.
6.- Works as a link among the items table and the orders one.

1 Like
  1. 1-1, 1-many, many-1, many-many, and self referencing
  2. when there is at most 1 record that links the two tables. For example, a table of customer names, may have 1-1 relationship with a table customer address
  3. both “customers” and "address’ have a column called “customer_id”. It is through this column that the two tables are linked together. Given a customer in the “Customer” table, you can find the corresponding recoding in the “address” table via “customer_id” column.
  4. “Customer” table and “Order” table is an example of “Many to One/One to Many” relationship. A customer can have any number of entries in the “order table”, but an order can only reference a customer.
  5. “Order” and “Item” table is an example of Many to many relationship. Each order can have one or more items, and each item can be in one or more orders.
  6. The “items_orders” table is to create Many to Many" relationship between the items and the orders. It is useful to visualize the relationship between items and orders.
1 Like
  1. i) one to one ii) one to many iii) many to one iv) many to many v) self referencing
  2. In relationships where a field is unique to one record. e.g. phone number
  3. In the address table the customer_id can be used as a foreign key, to match the customer with the address
  4. Many to one = all orders are associated with one customer ; One to many = one customer can be associated with many orders.
  5. Many to Many = friend relationships on Facebook
  6. Matches items and orders
1 Like

here we go:

RELATIONSHIPS

1.) What kinds of relationships can we represent in a database?
A.) There are several types of database relationships. commonly used examples below, to name a few:

i.) One to One Relationships
ii.)One to Many and Many to One Relationships
iii.) Many to Many Relationships
iv.)Self Referencing Relationships

When selecting data from multiple tables with relationships, the JOIN query is used. There are several types of ommonly used JOIN’s,examples below:

i.) Cross Joins
ii.) Natural Joins
iii.) Inner Joins
iv.)Left (Outer) Joins
v.) Right (Outer) Joins

2.) When do we use “One to One” relationships? Give an example from the real world.
A.) EXAMPLE: When a customer order need a delivery address you link the customer with the delivery address or billing address
3.) In the article in the “One to One”-section, the author of the article has a column called customer_id in the 4.) customers table. Why? How is it used in order to connect customers to addresses?
A.)customer_id = Address_id
5.) Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
A.) An Order can consist of many items Example: customer_id= Order_id= item_id= item_ description, amount, shipping and billing address.
6.) Give an example from the real world when would need to use a “Many to Many” relationship.
7.) What does items orders table do?
It links the customer to items purchased. (It creates a many to many relationship between customer and Items ordered. and at the end an income :stuck_out_tongue_winking_eye:

1 Like
  • 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, and Self Referencing Relationships.

  • When do we use “One to One” relationships? Give an example from the real world.
    When one key has one value, each student in the school has only one pin code.

  • 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 separate column that has customer_id because it separates the information from all of the customer’s information. It helps keep everything neat and it is easier to see how many customers there are and what their unique id is. Customer_id is needed to reference the customer with their appropriate information/data that is contained somewhere else in a set.

  • Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    Each student can take many classes but a class can only belong to one student.

  • Give an example from the real world when would need to use a “Many to Many” relationship.
    In Facebook there are many users who have liked the same photo or are part of the same group. The group and photos don’t only belong to one user but to many of them.

  • What does items_orders table do?
    Makes a many-to-many relationship.

1 Like
  1. In a DB you can represent all different relations you need like one2one, one2many, many2many or even self referencing one.

  2. One to one can be customer row referincing to address if we limit the user to have only one address.

  3. Customer_id is used as a primary key which will be used for referincing and as foreign key in other table.

  4. Many2One/One2Many can be where many orders can have one same customer, or where one customer can have multiple creditcards for payment.

  5. Many2many example is item orders table, where one order can have many items and also vice versa one item can be in many orders.

  6. Items_orders table is pure many to many relation table.

2 Likes
  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” relationship? Give an example from the real world.

One Record for one Attribute and Visa Versa – one attribute per record

  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 is called a “Foreign Key” and it used to combine queries between database tables

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

Many Records to one Attribute/Many Attributes

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

Where People / Groups are the records and Attributes, Many People can be members of Multiple Groups

  1. What does items_orders table do?

**Its one purpose, and that is to create a “Many to Many” relationship between databases by using their Foreign keys

1 Like
  1. One to one. One to many. Many to one. Many to many.
  2. Unique user with unique email.
    3.To match record from Customer Table to Address Table. Is called a Foreign Key and it is used for all kind of database relationships .
    4.Many to One: many people live on one street ( street name Broadfields Av)
    One to Many: one street (Broadfields Av.) in the city
    5.Cars: Car 1 has: AC, MP3 Player, Massage Seats
    Car 2 has: AC, MP3 Player, electric windows
    Car 3 has: AC, Radio Player, Massage Seats
    6.Is a Many to Many relationship between items and orders
1 Like
  1. What kinds of relationships can we represent in a database?
    A: One to 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.
    A: We use 1:1 when there is a unique entry with a unique piece of data. This might be a name paired to an employee ID number in an HR database.
  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?
    A: It is used as a Foreign Key
  4. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A: Items from a catalogue can be ordered by many customers and orders can contain multiple items.
  5. Give an example from the real world when would need to use a “Many to Many” relationship.
    A: A students class schedule where the class can have many students and the students can have many classes.
  6. What does items_orders table do?
    A: It creates a many to many relationship between the order table and the items table.
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.
  • A person can only have one father or mother related to him/her
  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?
  • A foreign Key connects Data between tables to create manageable tables that reated to another
  1. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    A costumer can have multiple orders.
  2. Give an example from the real world when would need to use a “Many to Many” relationship.
  • Students can have many courses and each course can be taken by many students.
  1. What does items_orders table do?
  • It holds the data for the many to many relationship between items and orders
1 Like