3

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.

Community
  • 1
  • 1
  • 1
    I think the OP wants this: Suppose you have three tables. Your main table has as its primary the most important (to the data design) key defined as a primary key. But. The other 2 tables have different primary keys. In order to make effieicent joins between table 1 and 2 or table 1 and 3, you may need to add the common column from the foreign table - a foreign key - to table 1. This is another way of looking at what you are trying to understand. Foreign keys the uniquely idnetify rows in rable 1 – jim mcnamara May 11 '13 at 20:53

2 Answers2

5

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.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

From, the above answer i came to this conclusion

Super key(one or more attributes used for selecting one or more rows)

                        ||
                        \/

Candidate key(one or more attributes from super used for selecting a single row)

                        ||  
                        \/

Primary key(one attribute among candidate keys used for selecting a single row)

Am i correct?

  • 2
    The **primary key** is **one of the candidate keys**, picked by you as the database designer. It's not *part* of a candidate key - it's **one of the existing, identified** candidate keys (the **whole** candidate key). – marc_s May 11 '13 at 21:26