eli5 What is a Candidate Key? [Normalisation Process]

117 views

I know it’s a basic question but I can find a simple answer.

Is it just multiple primary keys?

In: 19

3 Answers

Anonymous 0 Comments

A primary key is a set of attributes chosen by the user to uniquely identify a record. A candidate key is any set of attributes a user could pick to be that primary key. Making poor choices for the primary can serve as a good example.

Perhaps you want to inventory the dresses in your closet. You don’t have many, so simply referring to them by their color is sufficient to specifically refer to a particular dress. The red one. The black one. The blue one. You looked in your closet and noticed color was a candidate key, and selected that to be your primary key.

One day you buy a new blue dress. Oh no, now your primary key won’t work because “the blue one” could refer to either dress. You need to pick a new primary key, so you review your candidate keys. You could pick the order they appear in your closet (dress one, dress two, etc), but then you realize this new dress has pockets while the others don’t. So now you can say “the blue one with pockets” or “the black one without pockets”.

A good database design would try to think forward and cover all the future possibilities, or else simply assign a unique key to each new record in order to guarantee you won’t need to change your system in the future.

You are viewing 1 out of 3 answers, click here to view all answers.