Search code examples
sqlkeyrdbms

Difference between Primary key and Candidate key


I have read about Keys in RDBMS. https://stackoverflow.com/a/6951124/1647112 I however couldn't understand the need to use a candidate key. If a primary key is all that is needed to uniquely identify a row in a table, why is candidate key required? Please give a good example as to state the differences and importance of various keys. Thanks in advance.


Solution

  • A table can have one or more candidate keys - these are keys that uniquely identify a row in the table.

    However, only one of these candidate keys can be chosen to be the primary key.