Let's consider the topics with a basic example. Suppose we have a student table, that contains data for name, class, the section of students. Now, if we want to check data for students with a name, there might be the same names carried by two different students, or to make it more complex, there might be the case where 2 different students with the same name, class, and section exist.
How can those two entries be uniquely identified?
It can be done by introducing a new column into a table, that contains unique values. For students, the unique values can be considered as:
- Roll No.
- Adhar Number
- admission Number
- Student_ID
- Pan number
- Email ID
and a few more. Now, the above-mentioned list is nothing but a bucket of Candidate keys. Therefore it can be said that:
'Candidate Keys are nothing but a set of columns that has the capability to uniquely identify tuples or rows in a table.'
Now as we have a set of candidate keys, we choose one key that satisfies most with the situation, as a Primary key. Therefore, the keys that are in the bucket of candidate keys but not selected as a Primary Key are considered as Alternative Keys. For instance, you consider Roll No as a Primary key from the set of candidate keys the other ones that are Adhar Number, admission Number, Student_ID, Pan Number and Email ID are Alternate Keys.