Basic Rules for Identifying Primary Keys in a Relational Database
- Databases consist of tables made of rows of data. Each column in a table represents a specific field of information and can include differing types of data, such as numbers or text. A primary key is a field or group of fields in a database that make a unique identifier for each row of information. Primary keys are particularly important because they can connect tables within a database by referencing primary keys in other tables.
- Primary keys are often numeric values because they are easily incremented. Some database software offers an auto-incremented number option, which allows for an easy primary key field. This can also be a larger more complex number, such as an employee ID number.
- A static piece of information is information that will not be altered or updated over time. Look for information that is not subject to changes when identifying primary keys, such as ID numbers and not names.
- If a primary key is defined within a table, it will never have a null value. A piece of information cannot be referenced without a primary key, so the value is automatically required by the software. If a column contains any null values, it is not the primary key.
- A primary key can either be made from a single field or a combination of several fields. A primary key could be made from a combination of an employee ID number and the time the computer use started in a database containing computer use logs, for example.