Primary Key in DBMS

Rumman Ansari   Software Engineer   2023-03-23   6128 Share
☰ Table of Contents

Table of Content:


It is the first key which is used to identify one and only one instance of an entity uniquely. An entity can contain multiple keys as we saw in EMPLOYEE table. The key which is most suitable from those lists become a primary key.

In the EMPLOYEE table, Employee_ID can be primary key since it is unique for each employee. In the EMPLOYEE table, we can even select License_Number, Passport_Number and SSIN as primary key since they are also unique.

Another way we can say: Primary key is a candidate key that is most appropriate to become the main key for any table. It is a key that can uniquely identify each record in a table.

Points to Note regarding Primary Key

  • We denote usually denote it by underlining the attribute name (column name).
  • The value of primary key should be unique for each row of the table. The column(s) that makes the key cannot contain duplicate values.
  • The attribute(s) that is marked as primary key is not allowed to have null values.
  • Primary keys are not necessarily to be a single attribute (column). It can be a set of more than one attributes (columns). For example {Employe_Id, Employee_name} collectively can identify the tuple in the above table, but we do not choose it as primary key because Stu_Id alone is enough to uniquely identifies rows in a table and we always go for minimal set. Having that said, we should choose more than one columns as primary key only when there is no single column that can uniquely identify the tuple in table.