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?
- In a composite key, uniqueness is the tuple, not any single column. A UUID partner guarantees the tuple is unique even if every other column is identical across rows.
- This is common in many-to-many join tables where you still want a stable, addressable row.
How to generate
- Define the key as (entity_id, uuid) or (uuid, uuid).
- Index the lookup columns separately for fast queries.
- Use the UUID when you need to reference the junction row directly.
Use Cases
- User ↔ role membership rows.
- Product ↔ tag mappings.
- Graph edges identified by two node IDs.
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
UUID v1 GeneratorUUID v3 GeneratorUUID v4 GeneratorUUID v5 GeneratorUUID v6 GeneratorUUID v7 GeneratorUUID v8 GeneratorBulk UUID GeneratorShort UUID GeneratorUUID ValidatorUUID FormatterUUID as a Primary KeyUUID Database IDUUID Foreign KeyUUID Shard KeyUUID Partition KeyUUID in a Composite KeyUUID Surrogate KeyUUID API KeyUUID Session TokenUUID Access TokenUUID Refresh TokenUUID Idempotency KeyUUID Request IDUUID Correlation IDUUID Trace IDUUID CSRF TokenUUID NonceUUID FilenameUUID Object KeyUUID S3 KeyUUID Upload IDUUID Cache KeyUUID Blob NameUUID Temp FileUUID User IDUUID Account IDUUID Customer IDUUID Device IDUUID Tenant IDUUID Client IDUUID Anonymous IDUUID Member IDUUID Message IDUUID Event IDUUID Job IDUUID Task IDUUID Queue Message IDUUID Transaction IDUUID Order IDUUID Invoice IDUUID Payment IDUUID Reset TokenUUID Verification TokenUUID Invite CodeUUID API SecretUUID Share LinkUUID Magic LinkUUID Node IDUUID Worker IDUUID Lock IDUUID Cluster IDUUID Test DataUUID Seed DataUUID FixtureUUID Mock IDUUID Placeholder IDUUID Sample ID