UUID Use Case

UUID in a Composite Key

A composite key combines columns. Adding a UUID makes the combination unique regardless of the other fields, which is useful for join or mapping tables.

Multi-columnCollision-proofJoin tables

Generated locally with the Web Crypto API — nothing leaves your browser.

What Is UUID in a Composite Key?

How to generate

  1. Define the key as (entity_id, uuid) or (uuid, uuid).
  2. Index the lookup columns separately for fast queries.
  3. Use the UUID when you need to reference the junction row directly.

Use Cases

Code Examples

PostgreSQL
CREATE TABLE membership (
  user_id UUID,
  role_id UUID,
  row_id UUID DEFAULT gen_random_uuid(),
  PRIMARY KEY (user_id, role_id)
);

Frequently Asked Questions

Do I need a UUID in a composite key?
Only if you must address the junction row on its own, or if the natural columns alone are not unique. Otherwise the natural key suffices.
Does a UUID in the key bloat the index?
Slightly — 16 bytes per row. Acceptable for join tables; avoid it on huge fact tables.

Related tools