MS Access

All About The Primary Key

All About The Primary Key

At some point in our lives, all of us have come across this term called the primary key. So what’s the use of a primary key? Let us take an example to understand it in a better way. Suppose I have a firm, my own company, and I want to store the record of each person working in my organization. Then, when I have a few fields like DOB, date of joining, age, salary, and employment ID, there are certainly chances that any two records of two different persons can have almost everything similar. What I mean to say is two people, who have joined the company on the same date, have been offered the same salary package and coincidentally have their birthdays on the same date, and they may even have the same age also. Now, to make the situation worse, there may be one in a hundred cases where even the names of both persons become the same. ( I myself had five students named Ayush in my high school). So, it becomes a matter of confusion for the HR department to keep track of them, which may lead to serious misconceptions. So, in that case, We have to define a particular field, which we call the primary key, which will be unique for each employee. Each employee, here, in our example, can be assigned a unique employment id, which can serve as the primary key. It should be kept in mind that computers, as a device, originated as a military devices whose sole work was to coordinate with the military requirements. So, typically, the databases were created, creating a unique identification number, which would be similar to the unique military id assigned to each machine during the WW2 era. You can also think of it as the aadhar card number. There is a requirement to assign a field as a primary key. You cannot simply assign any field randomly to be the primary key. The main criterion is it should not contain similar data for 2 different entries. And then, no particular cell should be left vacant. If these two conditions are satisfied, then you are all ready to set that field as a primary key.