Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Primary key and Candidate key

Tags:

sql

key

rdbms

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.

like image 318
Shashank Raghunath Avatar asked Jul 08 '26 17:07

Shashank Raghunath


1 Answers

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.

like image 142
Oded Avatar answered Jul 11 '26 11:07

Oded