6.1 Primary Keys


Having two identical rows in a table can cause data redundancy and inconsistency problems.
A primary key ensures that each row in a table unique with no duplicate.
It is an attribute or a set of attribute that enable data in a table to be uniquely identified.
A table in a relational database must have a primary key.
For example,
Consider a university library database which includes a student member table shown in Figure 6.1.
The table has attributes such as name, phone number, matriculation number and department number.
The student’s matriculation number can be used as a primary key as it can uniquely identify a student record.
Attributes of a primary key are usually underlined.

The main characteristics of a primary key:
Must be minimal to avoid errors in data. Thus, in the example above, having (matriculation number, student name) attributes as primary key is not acceptable as matriculation number alone is sufficient.
Must consist of attributes that can never have NULL values. A NULL value could cause row duplication.


6.1 Primary Keys


Must be fixed and should never be changed once the table is populated with data.
Note that there could be more than one alternative attribute(s) that can uniquely identify rows in a table.
Only one of them can be chosen to be the primary key. The other alternatives are called Candidate Keys.