Junior — Middle
Can you list and explain the types of relationships between tables in a database?
sobes.tech AI
Answer from AI
In relational databases, there are three main types of relationships between tables:
-
One-to-One
- Each record in the first table corresponds to exactly one record in the second table and vice versa.
- Used when data is logically separated but directly related.
-
One-to-Many
- One record in the first table can correspond to many records in the second table.
- For example, one user can have many orders.
-
Many-to-Many
- Records in the first table can correspond to many records in the second table and vice versa.
- Implemented through an intermediate (linking) table that contains foreign keys of both tables.
These relationships help structure data and ensure integrity when working with it.