Keys in Relational Database

created:

updated:

tags: database

Types of Keys

There are several types of keys in relational database. They are super key, candidate key, primary key, alternate key, and foreign key.

Super Key

An attribute or attributes that distinguish the tuple as unique in the relation.

Candidate Key

An attribute or attributes that distinguish the tuple as unique with the minimum number of attributes in the relation.

Primary Key

One of the candidate keys that we use as a primary one for the relation. There must be one primary key for a relation.

What are some standards for choosing a primary key?

  • Attribute(s) that may have a NULL value is not suitable for the primary key.
    • NULL value cannot be used to distinguish tuples.
  • Attribute(s) whose value may change often is not suitable for the primary key.
    • If the value changes often, it is cumbersome to validate its eligibility as the primary key.
  • It is a good idea to choose a simpler candidate key as the primary key.
    • Simpler candidate key(s) such as integers or characters are note only good for users but also for computer system.

Alternate Key

The rest of the candidate keys besides the primary key.

Foreign Key

An attribute or attributes that refer to the primary key of other related relation.

References

  • 데이터베이스 개론 5장: 관계 데이터 모델