Primary key of a relational table is that key which identifies each and every record in a table uniquely. It can be either a normal attribute whose uniqueness is taken for guaranteed like SSN (Social Security Number) etc or can be generated or made available by the DBMS (Database Management System) like GUID (Globally Unique Identifier) in Microsoft SQL Server. It may consist of a single as well as multiple attributes in combination.

Let’s take an example of an EMPLOYEE table that contains a record for every single employee in an organization from lower to higher position. The employee’s unique employee ID number would be a primary key in the EMPLOYEE table. The employee’s first and last name would not be a primary key coz it can’t be taken for guaranteed that no two employees will have the same first name and last name.

Now create all the tables you will need for keeping track of the Employees in an organization. Let the first table be Employee and it will contain the list of all the employees with e-code (Employee code, numbers), employee’s first name and last name along with middle initials (text), gender (text 1), age (number) and mob (number). Second table will differentiate the employees position whether manager, peon etc and let it be e-pos.

As the tables were created its now turn to set the primary or foreign keys. The primary key of the Election table could be the e-code which would be unique code for every employee.

Step 1:

In order to set a primary key, click on the desired field or fields you want to make. To select a field click on the desired field or on the row-selector to select the entire row. As per the example taken above, click on e-code and then on the toolbar and click on primary to make it the primary key.

[Field that already has data or which returns a null value can’t be selected as a Primary Key, coz MS Access will not allow you to do that. It will generate a message at the time you save it.]

Step 2:

If you want to select multiple numbers of fields, then just hold down the ctrl key and click the row selector for each field you want and then on the toolbar and click on primary to make it the primary key.

Step 3:

The primary key is set. If you want to change a Primary key follow the same procedure as in step 1 and 2. But be sure that the field you want to make Primary does not have duplicate or null values. If in-case you face such problems, follow step 4.

Step 4:

Primary key can be set for a field that already has data in it but on doing so at the time of saving MS Access will generate a message if it finds any duplicate or null values in it. To sort out this situation you can either try to find duplicate query so as to locate the duplicate or null values and then edit the tracked field to remove them. Or else you can choose a different field.