Sobes.tech
Junior — Middle

What are the main criteria for choosing a primary key in a database?

sobes.tech AI

Answer from AI

Main criteria for choosing a primary key in a database:

  • Uniqueness: The key value must uniquely identify each record.
  • Immutability: The primary key value should not change over time.
  • Minimal size: It is better to choose a key with the smallest size for index optimization and performance.
  • Simplicity: The key should be simple to understand and use.
  • No NULLs: The primary key cannot contain NULL values.

Example: often auto-incrementing integer fields or UUIDs are used when global uniqueness is required.

What are the main criteria for choosing a primary key… - sobes.tech