Practice Discrete Math

Relations / Sql Keys Constraints

Least You Need to Know: Keys, Functional Dependencies, and Constraints

Database design questions are relation questions wearing engineering clothes. Keys identify tuples, foreign keys connect relations, and functional dependencies explain when one set of attributes determines another.

The least you need to know

Key notation

X → Y attribute set X functionally determines attribute set Y
PK primary key
FK foreign key referencing another relation's key

Tiny worked example

  • In `Employees(employee_id, email, team_id, team_name)`, the attribute `employee_id` may identify each row uniquely.
  • If `team_id` always determines `team_name`, then `team_id → team_name` is a functional dependency.
  • Repeating `team_name` in every employee row can create update anomalies if the team name changes.
  • Splitting team facts into a separate `Teams(team_id, team_name)` relation removes that repetition.

Common mistakes

How to recognize this kind of problem

Start practice