A secondary key is a key that has not been selected as a primary key. However, it is considered a candidate key for the primary key.
Therefore, candidate keys that are not selected as primary keys are called secondary keys. A candidate key is an attribute or set of attributes that you can think of as a primary key.
Note: Secondary keys are not foreign keys.
Let’s look at an example −
Student_ID | Student_Enroll | Student_Name | ##Student_Age | Student_Email |
9122717 |
Manish |
25 |
##aaa@gmail.com | 055 |
9122655 | Manan | 23 | abc@gmail.com | ##067 |
Shreyas | 28 | ##pqr@gmail.com |
Above, |
are candidate keys. They are considered candidate keys because they uniquely identify student records. Select one of the candidate keys as the primary key. The remaining two keys will become secondary keys.
Assume that you selected Student_ID as the primary key, so Student_Enroll and
Student_Emailwill become secondary keys (candidate keys for the primary key). ExampleLet’s look at another example −
Employee_ID
Employee_No | Employee_Name | Employee_Email | Employee_Dept | ##0989 | E7897
Jacob | ##jacob@example.com | Finance | 0777 |
E8768 |
Anna | anna@example.com | HR | ##0656 | E8789 |
tom@example.com | Operations | Above, Employee_ID, Employee_No and | Employee_Email
The above is the detailed content of Secondary keys in RDBMS. For more information, please follow other related articles on the PHP Chinese website!