Keys & ER Model

Keys uniquely identify rows and link tables. The ER model describes entities, attributes and relationships before building tables.

Cheat sheet

  • ▸Super key: any set that uniquely identifies a row.
  • ▸Candidate key: minimal super key. Primary key: chosen candidate key (NOT NULL).
  • ▸Alternate key: candidate keys not chosen as primary.
  • ▸Foreign key: references a primary key in another table.
  • ▸Composite key: key with multiple columns. Surrogate key: system-generated ID.
  • ▸Cardinality: 1:1, 1:N, M:N (M:N needs a junction table).

Primary vs Unique vs Foreign

KeyNULL allowed?Per tablePurpose
PrimaryNoOneRow identity
UniqueYes (usually one/many)ManyNo duplicates
ForeignYesManyReferential integrity

Top 10 campus interview questions

Quick quiz

1. A minimal super key is a:

2. Primary key can contain NULL?

3. M:N relationship is implemented using:

4. Weak entity is shown in ER with:

5. Foreign key ensures: