What if one key isn't enough to find exactly what you need? Discover how combining keys solves this!
Why Composite primary key in DynamoDB? - Purpose & Use Cases
Imagine you have a big notebook where you write down all your friends' phone numbers. But some friends have the same name, so when you look for a number, you get confused and sometimes write the wrong one.
Using just one name to find a phone number is slow and risky. You might call the wrong friend or waste time flipping through pages to find the right one. It's easy to make mistakes and hard to keep things organized.
A composite primary key is like using both your friend's name and their city to find their phone number. This way, you have two pieces of information working together to find exactly the right friend quickly and without mistakes.
Table with only 'Name' as partition key Find phone by name only
Table with 'Name' as partition key and 'City' as sort key (composite primary key) Find phone by name and city
It lets you uniquely identify and quickly find items even when one piece of information alone is not enough.
In an online store, many customers can have the same first name. Using a composite key like 'CustomerID' and 'OrderID' helps find the exact order for the right customer without confusion.
Composite keys combine two attributes to uniquely identify data.
This prevents confusion when one attribute alone is not unique.
It makes searching and organizing data faster and safer.