If you’ve been following along with some of our previous blog posts, you’ll know that we’ve discussed some of the more used keys when dealing with databases. Lest you forget, we talked about keys in these two blog posts:
Now, we can talk about some of the other keys in a database.
First, let’s talk about candidate keys. A candidate key has the following requirements:
- It must contain unique values
- Candidate key may have multiple attributes
- Must not contain null values
- It should contain minimum fields to ensure uniqueness
- Uniquely identify each record in a table
For example, in the following example, we have 3 different candidate keys.
For those of you playing at home, I have set up the next block of text so that you have to select the area to see what the candidate keys are.
The candidate keys are PersonID, EmailAddress, and EmployeeID. Email Address can be used as a primary key here because this is an internal email address that our great security team can ensure that everyone will have a unique email – otherwise, this would be an awful choice.
Our next type of key is an Alternate Key. An alternate key is those candidate keys that were not selected to become the Primary Key.
In our case, the PersonID is most certainly not an alternate key because it is the primary key of this table. The other candidate keys are the alternate keys.
(Did you think I was going to tell you what those candidate keys were without having you highlight the block of text above?)
Not this time, me bucko.
Maybe next time.
(Probably not, but you can certainly try.)
Won’t get you very far though.
So, next time we’ll go over the remaining types of keys – yes, I know some of you are quite surprised that there are this many! – and we’ll tie up the fun with database keys series. Until next time!