Sobes.tech
Junior — Middle

Can you name the main types of relationships that exist between tables in a relational database?

sobes.tech AI

Answer from AI

Main types of relationships between tables in a relational database:

  1. One-to-One — each record in the first table corresponds to exactly one record in the second table.
  2. One-to-Many — one record in the first table corresponds to multiple records in the second.
  3. Many-to-Many — records in the first table can correspond to multiple records in the second and vice versa. Usually implemented through an intermediate join table.

For example, in a store database:

  • One customer (Customers table) can have many orders (Orders) — a one-to-many relationship.
  • One order is associated with one customer — the inverse relationship.
  • Products and orders are related many-to-many, as one order can contain multiple products, and one product can be in multiple orders.