SQL Relationships - Reading Assignment


#41
  1. What kinds of relationships can we represent in a database?
  • one to one rel.
  • one to many and many to one rel.
  • many to many rel.
  • self referencin rel.
  1. When do we use “One to One” relationships? Give an example from the real world.
    when there can be only an attribute can only be matched to exactly one other attribute.
    lets say in table 1 you have the e-mail Address and password of a user. and in table 2 you have the usernames. each username can only be link to one email and to one password. each email can only be related to one username.

  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?
    Each customer id gets one adress Id. this foreign key is then used to find the address. To do so you would enter the customer id, from that you derive the address Id and from there you get the address from the address table.

  3. Give an example from the real world when would need to use a “Many to One/One to Many” relationship.
    When the children are related to a father. there can by two children, none, or one child be related to one father. Probably you would use a many to many because the children are also related to a mother.
    another example could be picture to profile pictures on FB. Because you can have many profile pictures.

  4. Give an example from the real world when would need to use a “Many to Many” relationship.
    children to parents. each child has two parents, and each parent can have 0, 1, 2, etc. children

  5. What does items_orders table do?
    It links items to the orders


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

Ans :

  • 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.

Ans : It refers to relationships of two items in which one can only belong with the other. They are a pair.

Example : Santa Claus is associated with one holiday.

  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?

Ans : This is done for storing a relationship between the customer and the address. Foreign key is used in order to connect customers to addresses.

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

Ans : One to many/Many to one : if you have a list of works of art and a list of museums, each work of art can only be in one museum at a time, but each museum can have many works of art.

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

Ans : Many to many : if you have a list of books, and a list of authors , each book may have one or more authors, and each author may have written multiple books.

  1. What does items_orders table do?

Ans : items_orders is representing a many-to-many relationship. The Items_Orders table is working as Junction between those two tables so this table is also known as junction table .