0PricingLogin
SQL Academy · Lesson

Choosing Keys and Types

Pick BIGSERIAL vs UUID primary keys, decide between TEXT and VARCHAR(n), and choose the right type for every column.

Picking a Primary Key

Three real choices:

  1. BIGSERIAL — monotonically increasing 64-bit integer
  2. UUID — 128-bit globally unique
  3. Natural key — a real-world identifier (email, ISBN)

When BIGSERIAL Wins

Default choice for most apps:

  • Small (8 bytes), fast index, cache-friendly
  • Monotonic → recent data clusters at the end of the index
  • Readable in URLs (e.g. /posts/42)

All lessons in this course

  1. Modelling a Blog: Users Posts Comments
  2. Choosing Keys and Types
  3. Indexes for Common Queries
  4. Seeding the Database with Test Data
← Back to SQL Academy