Sobes.tech
Junior — Middle

In which cases is it recommended to use natural keys in a database?

sobes.tech AI

Answer from AI

Natural keys in a database are keys that already exist in the domain and uniquely identify a record (e.g., passport number, TIN, email).

It is recommended to use natural keys when:

  • The key value is stable and does not change over time.
  • The key is truly unique and unambiguously identifies the record.
  • The key is short and simple for indexing.
  • There is no need for an additional surrogate key (e.g., auto-increment ID).

For example, in a user table, email can serve as a natural key if it is unique and does not change.

However, if the natural key can change or is complex, it is better to use a surrogate key.

In which cases is it recommended to use natural keys… - sobes.tech