Primary Key (Entity Relationship Diagram)
A primary key (usually abbreviated as PK) is a unique identifier for a set of tuples defined for the entity.
A primary key can be a single attribute or a set of multiple attributes.
Primary Key Symbol
The primary key can be depicted using one of these three styles:
- Plus (+)
- Abbreviation (PK)
- Key Icon (🔑)
The attributes of the primary key are rendered with bold.
How to Identify Primary Key
There are several factors to consider when identifying primary keys in a model entities:
- Uniqueness - The primary key must be unique for each record in the table. This means that no two records can have the same primary key value.
- Non-nullability - The primary key cannot contain a null value. This ensures that each record has a unique identifier.
- Minimization of key size - The primary key should be as small as possible, while still maintaining its uniqueness. This can help to optimize the performance of the database.
- Stability - The primary key should not change over time. If the key value needs to be modified, it is generally best to create a new record with a new primary key, rather than modifying the existing key value.
To identify the primary key for an entity, you can consider the characteristics of the data and the business requirements of the system. Some common options for primary keys include:
- auto-incrementing integer (such as an ID number)
- combination of multiple columns (such as a combination of document number and year)
- unique identifier that is generated by the system (such as a GUID)
Primary Key Example
In the real world, if the entity is an apartment, the primary key can be the number of the apartment.
How to Set Primary Key for ERD Entity
Our ERD tool offers various options how to set primary key to an ERD entity:
- Right-click on the ERD entity attribute and choose Primary Key from the context menu
- Select an ERD entity attribute and click on the Primary Key button in the ribbon / Field tab / Modifiers group.
- Edit the ERD entity attribute text in the diagram editor and type + before the attribute name
- Open the Properties dialog for the ERD entity (choose Properties from the context menu after right-clicking the ERD entity), switch to the Attributes tab, and check the PK check box for the attribute (or attributes) that should be the primary key for the entity.
You can check out this tutorial about setting the primary key.