What is a Secondary Key in DBMS?

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

Keys in DBMS are attributes or sets of attributes that help uniquely identify rows in a table. A table can have multiple columns or a set of columns that uniquely identify the rows. Now all the columns or sets of columns that uniquely identify the rows are called the candidate keys. The set of candidate keys is called super keys. Out of all the candidate keys, one is chosen as the primary key, and the rest of the candidate keys that have not been chosen to be candidate keys are called secondary keys in DBMS.

In other words, Secondary key in DBMS is a column or a set of columns in a table that uniquely identifies each row in a table that is not the primary key. Secondary keys are also called alternate keys as they can also be used alternatively in place of the primary key.

Examples

Look at the example below to understand secondary keys.

Class_IDStudent_IDEnrollment_NONameCourse_ID
AB235683ManishSN243
AC425628ShreyaDF412
AC235629KartikSN243
AB415610RajeshDF901
AB785719MananYU431
AB465412DishaYU431
AC465513TinaOP994

In the above table, we can uniquely identify students by their enrollment numbers. Class ID along with student ID can also uniquely identify the students as no two students in a class are going to have the same student ID. Thus, Enrollment_NO and Class_ID + Student_ID are the two candidate keys as both of them can be used as the primary key to identify the rows uniquely for valid student data.

So, we can select one of them as the primary key let's say, Enrollment_NO is chosen as the primary key then, Class_ ID + Student_ID is said to be the secondary key.

What is the Difference Between a Primary Key And a Secondary Key in DBMS?

The key difference between a primary key and a secondary key in DBMS is, the primary key is chosen by the administrator for identifying each row uniquely whereas, candidate keys that are not selected for the primary key are called secondary keys.

Secondary keys have all the properties of the primary key, it is perfectly capable of determining tuples uniquely in the table.

BasisPrimary KeySecondary Key
DefinitionA key that is unique, not null, and is selected by the database administrator to uniquely identify tuples is called the primary key.A key that uniquely identifies rows but is not selected as the primary key is known as a secondary key or alternate key.
NULL valuesIt cannot be NULL.It can be NULL.
Number of keysThere must be one and only one primary key.There can be zero or more secondary keys.

Conclusion

  • Secondary keys are also called alternate keys. They uniquely identify rows in a table and thus can be used alternatively as primary keys.
  • From the set of candidate keys, only one primary key is chosen by the database administrator, and the rest of the candidate keys are called secondary keys.
  • There is only one primary key but there can be no secondary key or it can be more than one.

Read More: