What are the different types of relationships in database design?

Instruction: List and briefly describe the various types of relationships that can exist between database tables.

Context: This question evaluates the candidate's grasp of relational database concepts, specifically the ways tables can be related to each other.

Updated

Official answer

The common cardinalities describe how many related rows can exist:

  • One-to-one: a profile belongs to one user, and each user has at most one profile. A unique foreign key, often also the profile's primary key, enforces the at-most-one side. It does not force every user to have a profile.
  • One-to-many: one customer can have many orders, while each order references one customer. A non-NULL foreign key on orders makes that reference mandatory, but the customer may still have zero orders.
  • Many-to-many: an article can have several tags and a tag can describe several articles. Use article_tags(article_id, tag_id) with two foreign keys and a unique pair to prevent duplicate memberships.

Separate maximum cardinality from optionality: zero-or-one differs from exactly one. A diagram alone does not enforce either. Translate the chosen rules into supported keys, constraints and transaction-safe application behavior, then test duplicate links, absent parents and deletion policies.

Relationships can reference the same entity type, as in employee/manager, and can carry attributes, such as enrollment date on a student/course link. Model those facts at the relationship's own grain.

Related Questions